Changeset 485 for trunk/email2trac.py.in


Ignore:
Timestamp:
10/06/10 15:18:04 (13 years ago)
Author:
bas
Message:

added parentdir functionality, see #217

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r484 r485  
    20662066                sys.exit(1)
    20672067
    2068         config = trac_config.Configuration(file)
    2069 
    2070         ## Use given project name else use defaults
    2071         #
     2068        config = trac_config.Configuration(file)
     2069       
     2070        parentdir = config.get('DEFAULT', 'parentdir')
     2071        sections = config.sections()
     2072
     2073        ## use some trac internals to get the defaults
     2074        #
     2075        tmp = config.parser.defaults()
     2076        project =  SaraDict()
     2077
     2078        for option, value in tmp.items():
     2079                try:
     2080                        project[option] = int(value)
     2081                except ValueError:
     2082                        project[option] = value
     2083
    20722084        if name:
    2073                 sections = config.sections()
    2074                 if not name in sections:
    2075                         print "Not a valid project name: %s" %name
    2076                         print "Valid names: %s" %sections
     2085                if name in sections:
     2086                        project =  SaraDict()
     2087                        for option, value in  config.options(name):
     2088                                try:
     2089                                        project[option] = int(value)
     2090                                except ValueError:
     2091                                        project[option] = value
     2092
     2093                elif not parentdir:
     2094                        print "Not a valid project name: %s, valid names are: %s" %(name, sections)
     2095                        print "or set parentdir in the [DEFAULT] section"
    20772096                        sys.exit(1)
    20782097
    2079                 project =  SaraDict()
    2080                 for option, value in  config.options(name):
    2081                         try:
    2082                                 project[option] = int(value)
    2083                         except ValueError:
    2084                                 project[option] = value
    2085 
    2086         else:
    2087                 ## use some trac internals to get the defaults
    2088                 #
    2089                 tmp = config.parser.defaults()
    2090                 project =  SaraDict()
    2091 
    2092                 for option, value in tmp.items():
    2093                         try:
    2094                                 project[option] = int(value)
    2095                         except ValueError:
    2096                                 project[option] = value
     2098        ## If parentdir the set project dir to parentdir + name
     2099        #
     2100        if not project.has_key('project'):
     2101                if not parentdir:
     2102                        print "You must set project or parentdir in your configuration file"
     2103                        sys.exit(1)
     2104                elif not name:
     2105                        print "You must set project in your configuration file"
     2106                else:
     2107                        project['project'] = os.path.join(parentdir, name)
    20972108
    20982109        return project
     
    23022313                        logger.debug('Loading environment %s', settings.project)
    23032314
    2304                 env = Environment(settings['project'], create=0)
     2315                try:
     2316                        env = Environment(settings['project'], create=0)
     2317                except IOError, detail:
     2318                        print "Trac project does not exists: %s" %(settings['project'])
     2319                        sys.exit(1)
    23052320
    23062321                tktparser = TicketEmailParser(env, settings, logger, float(version))
Note: See TracChangeset for help on using the changeset viewer.