From: James French Date: Mon, 2 Aug 2010 05:54:34 +0000 (+0800) Subject: Loads rules from a source file X-Git-Tag: 0.7~5 X-Git-Url: https://git.ucc.asn.au/?p=frenchie%2Ficalparse.git;a=commitdiff_plain;h=48d87039714129b0798a4efba2938d15190af7d8 Loads rules from a source file --- diff --git a/icalparse.py b/icalparse.py index a492dfa..1ed6076 100755 --- a/icalparse.py +++ b/icalparse.py @@ -150,6 +150,18 @@ def getHTTPContent(url='',cache='.httplib2-cache'): return '' + +def generateRules(): + '''Attempts to load a series of rules into a list''' + try: + import parserrules + except ImportError: + return [] + + rules = [getattr(parserrules, rule) for rule in dir(parserrules) if callable(getattr(parserrules, rule))] + return rules + + if __name__ == '__main__': from optparse import OptionParser # If the user passed us a 'stdin' argument, we'll go with that, @@ -174,4 +186,5 @@ if __name__ == '__main__': content = getContent(url, options.stdin) cal = lineJoiner(content) ical = splitFields(cal) - print ical + rules = generateRules() + print rules diff --git a/parserrules.py b/parserrules.py new file mode 100644 index 0000000..61a09e5 --- /dev/null +++ b/parserrules.py @@ -0,0 +1,18 @@ +#!/usr/bin/python + +# This file describes a series of rules which will be called on an ics file as +# rule(key, value) + +# Your functions are expected to return a (key, value) tuple or they will be treated as +# if they don't exist (ie, the line will go through unhindered). Returning a value which +# is boolean False will remove the offending line from the final ICS. The easiest way +# to pass a line back without changing it is to return True. + +# The doc string will be presented to the user when run as verbose, so please be polite + +def markEventsPublic(key, value): + '''Marking private events public''' + # Required as google are strict about the CLASS:PRIVATE/CLASS:CONFIDENTIAL lines + if key == 'CLASS': + return (key, 'PUBLIC') + return True diff --git a/rules.py b/rules.py deleted file mode 100644 index 61a09e5..0000000 --- a/rules.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python - -# This file describes a series of rules which will be called on an ics file as -# rule(key, value) - -# Your functions are expected to return a (key, value) tuple or they will be treated as -# if they don't exist (ie, the line will go through unhindered). Returning a value which -# is boolean False will remove the offending line from the final ICS. The easiest way -# to pass a line back without changing it is to return True. - -# The doc string will be presented to the user when run as verbose, so please be polite - -def markEventsPublic(key, value): - '''Marking private events public''' - # Required as google are strict about the CLASS:PRIVATE/CLASS:CONFIDENTIAL lines - if key == 'CLASS': - return (key, 'PUBLIC') - return True