Changeset 18 for emailtotracscript


Ignore:
Timestamp:
01/10/06 23:09:17 (18 years ago)
Author:
bas
Message:

EmailtoTracScript?:

emailtotracscript:

  • Removed project_root option from config file
  • Removed some obsolete code
  • Added multiple stanza's for config file, selectable
with --projectp option
  • email2trac.conf example for mulitple projects
Location:
emailtotracscript/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • emailtotracscript/trunk/ChangeLog

    r16 r18  
     12006-01-10  Bas van der Vlies <basv@sara.nl>:
     2        * Removed project_root from source and config file
     3        * Adjust code so we can use mulitple stanza's in config file, eg:
     4          [bas]
     5          project: /data/trac/bas
     6          spam_level: 3
     7
     8          use option "-p|--project bas" to select the stanza
     9
    1102006-01-04  Bas van der Vlies <basv@sara.nl>:
    211
  • emailtotracscript/trunk/email2trac.conf

    r7 r18  
    1010email_header: 1
    1111trac_version: 0.9
     12
     13[bas]
     14project: /data/trac/bas
     15spam_level: 1
  • emailtotracscript/trunk/email2trac.py

    r10 r18  
    4747----------
    4848 * Create an config file:
    49         [DEFAULT]                    # REQUIRED
    50         project: /data/trac/test     # REQUIRED
    51         debug: 1                     # OPTIONAL, if set print some DEBUG info
    52         spam_level: 4                # OPTIONAL, if set check for SPAM mail
    53         reply_address: 1             # OPTIONAL, if set then fill in ticket CC field
    54         umask: 022                   # OPTIONAL, if set then use this umask for creation of the attachments
    55         mailto_link: 1               # OPTIONAL, if set then [mailto:<CC>] in description
    56         trac_version: 0.8            # OPTIONAL, default is 0.9
     49        [DEFAULT]                        # REQUIRED
     50        project      : /data/trac/test   # REQUIRED
     51        debug        : 1                 # OPTIONAL, if set print some DEBUG info
     52        spam_level   : 4                 # OPTIONAL, if set check for SPAM mail
     53        reply_address: 1                 # OPTIONAL, if set then fill in ticket CC field
     54        umask        : 022               # OPTIONAL, if set then use this umask for creation of the attachments
     55        mailto_link  : 1                 # OPTIONAL, if set then [mailto:<CC>] in description
     56        trac_version : 0.8               # OPTIONAL, default is 0.9
     57
     58        [jouvin]                         # OPTIONAL project declaration, if set both fields necessary
     59        project      : /data/trac/jouvin # use -p|--project jouvin. 
    5760       
    5861 * default config file is : /etc/email2trac.conf
     
    449452
    450453
    451 def ReadConfig(file):
     454def ReadConfig(file, name):
    452455        """
    453456        Parse the config file
     
    459462
    460463        config = ConfigParser.ConfigParser()
    461 
    462464        try:
    463           config.read(file)
     465                config.read(file)
    464466        except ConfigParser.MissingSectionHeaderError,detail:
    465           print detail
    466           sys.exit(1)
    467 
    468         defaults = config.defaults()
    469         if not defaults.has_key('project') and  not defaults.has_key('project_root'):
    470                 print 'You have to define the location of your trac project'
    471                 print 'or the root of your projects, eg:'
    472                 print '\t project: /var/trac/<projectname>'
    473                 print '\t project_root: /var/trac'
    474                 sys.exit(1)
    475          
    476         return defaults
    477 
     467                print detail
     468                sys.exit(1)
     469
     470
     471        # Use given project name else use defaults
     472        #
     473        if name:
     474                if not config.has_section(name):
     475                        print "Not an valid project name: %s" %name
     476                        print "Valid names: %s" %config.sections()
     477                        sys.exit(1)
     478
     479                project =  dict()
     480                for option in  config.options(name):
     481                        project[option] = config.get(name, option)
     482
     483        else:
     484                project = config.defaults()
     485
     486        return project
    478487
    479488if __name__ == '__main__':
     
    481490        #
    482491        configfile = '/etc/email2trac.conf'
     492        configfile = './email2trac.conf'
    483493        project = ''
    484494        component = ''
     
    491501                sys.exit(1)
    492502
     503        project_name = None
    493504        for opt,value in opts:
    494505                if opt in [ '-h', '--help']:
     
    500511                        configfile = value
    501512                elif opt in ['-p', '--project']:
    502                         project = value
    503 
    504         settings = ReadConfig(configfile)
    505 
    506         if not settings.has_key('project') and not project:
    507                 print 'You must specify a project either in configuration file'
    508                 print 'or with option --project'
     513                        project_name = value
     514
     515        settings = ReadConfig(configfile, project_name)
     516        if not settings.has_key('project'):
     517                print __doc__
     518                print 'No project defined in config file, eg:\n\t project: /data/trac/bas'
    509519                sys.exit(1)
    510                
    511         if project:
    512                 if settings.has_key('project_root') :
    513                         settings['project'] = os.path.join(settings['project_root'], project)
    514                 else:
    515                         print 'You must specify a project root in configuration file'
    516                         print 'in order to use option --project'
    517                         sys.exit(1)
    518         else:
    519                 if not re.search("/",settings['project']):
    520                         if settings.has_key('project_root') :
    521                                 settings['project'] = os.path.join(settings['project_root'], settings['project'])
    522                         else:
    523                                 print 'You must specify a project root in configuration file'
    524                                 print 'or specify the project full path'
    525                                 sys.exit(1)
    526520
    527521        if component:
     
    532526        else:
    533527                version = trac_default_version
     528
     529        #debug HvB
     530        #print settings
    534531
    535532        if version > 0.8:
Note: See TracChangeset for help on using the changeset viewer.