Changeset 621 for trunk/email2trac.py.in


Ignore:
Timestamp:
06/17/13 21:25:11 (11 years ago)
Author:
bas
Message:

added support for trac installations in a virtual environment, eg:

  • configure --virtualenv=/data/virtualenvs/trac
  • set/override it with email2trac --virtualenv=/data/virtualenv/trac_1.2

Updated release version to 2.7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r620 r621  
    3939                -h,--help
    4040                -d, --debug
     41                -e, --virtualenv <path>
    4142                -f,--file  <configuration file>
    4243                -n,--dry-run
     
    4748        $Id$
    4849"""
    49 
    50 ### virualenv
    51 ##
    52 #        if virtualenv and os.path.exists(virtualenv):
    53 #                activate_this = os.path.join(virtualenv,
    54 #'bin/activate_this.py')
    55 #               if os.path.exists(activate_this):
    56 #                        execfile(activate_this,
    57 
    5850import os
    5951import sys
     
    7668from datetime import timedelta, datetime
    7769from stat import *
    78 
    79 try:
    80     from trac import __version__ as trac_version
    81     from trac import config as trac_config
    82 
    83 except ImportError, detail:
    84     print "Can not find a a valid trac installation, try setting PYTHONPATH"
    85     sys.exit(1)
    8670
    8771## Some global variables
     
    17931777        self.logger.info('subject: %s' %repr(subject))
    17941778
     1779        ## Ticket id is in Delivered-To Field. Trac notify must send this
     1780        #
     1781        #try:
     1782        #    print self.parameters.project_name
     1783        #    print 'Delivered To', m['Delivered-To']
     1784        #    print self.parameters.to_parse_address_delimiter
     1785        #    id = m['Delivered-To'].split(self.parameters.to_parse_address_delimiter)[1]
     1786        #    print id
     1787        #    id = id.split('@')[0]
     1788        #    print id
     1789#
     1790#        except KeyError, detail:
     1791#            pass
     1792
     1793
    17951794        ## [hic] #1529: Re: LRZ
    17961795        #  [hic] #1529?owner=bas,priority=medium: Re: LRZ
     
    26032602    verbose = None
    26042603    debug_interactive = None
    2605 
    2606     SHORT_OPT = 'cdhf:np:t:v'
    2607     LONG_OPT  =  ['component=', 'debug', 'dry-run', 'help', 'file=', 'project=', 'ticket_prefix=', 'verbose']
     2604    virtualenv = '@virtualenv@'
     2605
     2606    SHORT_OPT = 'cde:hf:np:t:v'
     2607    LONG_OPT  =  ['component=', 'debug', 'dry-run', 'help', 'file=', 'project=', 'ticket_prefix=', 'virtualenv=', 'verbose']
    26082608
    26092609    try:
     
    26232623        elif opt in ['-d', '--debug']:
    26242624            debug_interactive = 1
     2625        elif opt in ['-e', '--virtualenv']:
     2626            virtualenv = value
    26252627        elif opt in ['-f', '--file']:
    26262628            configfile = value
     
    26332635        elif opt in ['-v', '--verbose']:
    26342636            verbose = True
     2637
     2638    if virtualenv and os.path.exists(virtualenv):
     2639        activate_this = os.path.join(virtualenv, 'bin/activate_this.py')
     2640        if os.path.exists(activate_this):
     2641            execfile(activate_this, dict(__file__=activate_this))
     2642
     2643    try:
     2644        from trac import __version__ as trac_version
     2645        from trac import config as trac_config
     2646
     2647    except ImportError, detail:
     2648        print "Can not find a a valid trac installation, solutions could be:"
     2649        print "\tset PYTHONPATH"
     2650        print "\tuse the --virtualenv <dir> option"
     2651        sys.exit(1)
    26352652   
    26362653    settings = ReadConfig(configfile, project_name)
     
    27192736            logger.error("trac error: %s" %detail)
    27202737            sys.exit(0)
     2738        except TracError, detail:
     2739            logger.error("trac error: %s" %detail)
     2740            sys.exit(0)
    27212741
    27222742        tktparser = TicketEmailParser(env, settings, logger, float(version))
Note: See TracChangeset for help on using the changeset viewer.