Changeset 3135

Show
Ignore:
Timestamp:
01/23/08 09:53:42 (1 year ago)
Author:
andrei2102
Message:
  • the svn hooks now work even if the installation has multiple site-packages directories
    the site-path of the egg is written in a file in the tmp directory
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracsvnpoliciesplugin/0.11/svnpolicies/api.py

    r3125 r3135  
    11# -*- coding: utf-8 -*- 
    22# 
    3  
    43 
    54 
     
    98from pkg_resources import Requirement, resource_string, resource_filename 
    109 
    11 all= ['IniReader', 'validate_email', 'get_global_configurations', 'get_resource_path', 'get_hook_path'] 
     10all= ['IniReader',  
     11      'validate_email',  
     12      'get_global_configurations',  
     13      'get_resource_path',  
     14      'get_hook_path', 
     15      'get_site_packages'] 
     16 
     17def get_site_packages(): 
     18    return path.sep.join(__file__.split(path.sep)[:-3]) 
    1219 
    1320def validate_email(email): 
     
    5360    """ 
    5461    """ 
    55     # exctract the loader 
    56     resource_filename(Requirement.parse("TracSVNPoliciesPlugin"),"/svnpolicies/hooks/loader.py" ) 
     62     
     63    # exctract the loader and get the path 
     64    loader_path =resource_filename(Requirement.parse("TracSVNPoliciesPlugin"), "/svnpolicies/hooks/loader.py" ) 
     65    hooks_directory = path.sep.join(loader_path.split(path.sep)[:-1]) 
     66    # write the packages.pth file 
     67    pth_file = hooks_directory + path.sep + 'packages.pth' 
     68    hook_file = hooks_directory + path.sep + hook_name 
     69    if not path.isfile(pth_file) or not path.isfile(hook_file): 
     70        sitepck_dir = get_site_packages() 
     71        file_handler = file(pth_file,'w') 
     72        file_handler.write(sitepck_dir) 
     73        file_handler.close() 
     74     
    5775    # return the resource name 
    5876    return get_resource_path("/svnpolicies/hooks/" + hook_name) 
  • tracsvnpoliciesplugin/0.11/svnpolicies/hooks/loader.py

    r3124 r3135  
    1 from pkg_resources import Requirement, resource_string 
     1 
     2import os 
    23 
    34_variables = None 
    45 
    5 def get_global_configurations(variable_name=None): 
     6def get_real_path(link, cut_by=2): 
    67    """ 
    7     Reads the plugin configuration file and returns all the values  
    8     in a dictionary or the variable_name passed as parameter. 
     8    This function determines the real file that hides under symlinks. 
    99     
    10     @param variable_name: String 
     10    @return: String 
     11    @param link: String 
    1112    """ 
    12     global _variables 
    13     if _variables is not None : 
    14         if _variables.has_key(variable_name) : 
    15             return _variables[variable_name] 
    16     global_conf = resource_string(Requirement.parse("TracSVNPoliciesPlugin"), '/svnpolicies/svnpolicy.conf') 
    17     prev = locals().copy() 
    18     exec(global_conf) 
    19     next = locals().copy() 
    20     next.pop('prev') 
    21     _variables={} 
    22     for value_name in next.keys() : 
    23         if not prev.has_key(value_name): 
    24             _variables[value_name] = next[value_name] 
    25     if variable_name is not None: 
    26         if _variables.has_key(variable_name) : 
    27             return _variables[variable_name] 
    28     return _variables 
     13    hook_file= os.path.realpath(link) 
     14    return os.path.sep.join(hook_file.split(os.path.sep)[:-cut_by]) 
    2915 
     16def get_trac_path(link, cut_by=2): 
     17    """ 
     18    This function determines the target of a symlink. 
     19     
     20    @return: String 
     21    @param link: String 
     22    """ 
     23    hook_file= os.readlink(link) 
     24    return os.path.sep.join(hook_file.split(os.path.sep)[:-cut_by]) 
    3025 
    31 production= True 
     26PYTHONPATH = '' 
     27production= False 
    3228try : 
    3329    from svnpolicies import api 
    3430except Exception : 
    3531    import site 
    36     site.addsitedir(get_global_configurations('PYTHON_SITE_DIR')) 
     32    # get the python path from the pth file 
     33    pth_handle = file(get_real_path(__file__, 1) + os.sep +'packages.pth','r') 
     34    PYTHONPATH = pth_handle.readline().strip() 
     35    pth_handle.close() 
     36    # load it 
     37    site.addsitedir(PYTHONPATH) 
    3738    production= True 
    3839    from svnpolicies import api 
    3940 
    40 AUTHOR_URL_TEMPLATE= get_global_configurations('AUTHOR_URL_TEMPLATE'); 
    41 CHANGESET_URL= get_global_configurations('CHANGESET_URL'); 
    42 SVNNOTIFY= get_global_configurations('SVNNOTIFY'); 
    43 SVNLOOK= get_global_configurations('SVNLOOK'); 
    44 SMTP_HOST= get_global_configurations('SMTP_HOST'); 
    45 SMTP_USER= get_global_configurations('SMTP_USER'); 
    46 SMTP_PASSWORD= get_global_configurations('SMTP_PASSWORD'); 
    47 CREDENTIALS= "-S" + \ 
     41AUTHOR_URL_TEMPLATE = api.get_global_configurations('AUTHOR_URL_TEMPLATE'); 
     42CHANGESET_URL = api.get_global_configurations('CHANGESET_URL'); 
     43SVNNOTIFY = api.get_global_configurations('SVNNOTIFY'); 
     44SVNLOOK = api.get_global_configurations('SVNLOOK'); 
     45SMTP_HOST = api.get_global_configurations('SMTP_HOST'); 
     46SMTP_USER = api.get_global_configurations('SMTP_USER'); 
     47SMTP_PASSWORD = api.get_global_configurations('SMTP_PASSWORD'); 
     48CREDENTIALS = "-S" + \ 
    4849            " --smtp " + SMTP_HOST + \ 
    4950            " --smtp-user " + SMTP_USER + \ 
    5051            " --smtp-password " + SMTP_PASSWORD 
    5152 
    52 PYTHONPATH= get_global_configurations('PYTHON_SITE_DIR') 
     53TRAC_CODE_PATH = api.get_global_configurations('TRAC_CODE_PATH'); 
    5354 
    54 TRAC_CODE_PATH=get_global_configurations('TRAC_CODE_PATH'); 
    55  
  • tracsvnpoliciesplugin/0.11/svnpolicies/hooks/post-commit.py

    r3124 r3135  
    2222    if PYTHONPATH != "" and production: 
    2323        prefix= "export \"PYTHONPATH=%s\"; \n" % PYTHONPATH 
    24  
     24    print prefix 
    2525    p = subprocess.Popen(prefix + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 
    2626    out_text= p.stdout.readlines() 
     
    9494            "-U", CHANGESET_URL % (project_name, '%s')]) 
    9595    return command 
    96  
    97 def get_trac_path(link): 
    98     """ 
    99     This function determines the target of a symlink. 
    100      
    101     @return: String 
    102     @param link: String 
    103     """ 
    104     hook_file= os.readlink(link) 
    105     return os.path.sep.join(hook_file.split(os.path.sep)[:-2]) 
    106  
    107 def get_real_path(link): 
    108     """ 
    109     This function determines the real file that hides under symlinks. 
    110      
    111     @return: String 
    112     @param link: String 
    113     """ 
    114     hook_file= os.path.realpath(link) 
    115     return os.path.sep.join(hook_file.split(os.path.sep)[:-2]) 
    11696 
    11797 
  • tracsvnpoliciesplugin/0.11/svnpolicies/hooks/pre-commit.py

    r3124 r3135  
    9696                return False 
    9797    return True 
    98      
    99 def get_real_path(link): 
    100     """ 
    101     This function determines the real file that hides under symlinks. 
    102      
    103     @return: String 
    104     @param link: String 
    105     """ 
    106     hook_file= os.path.realpath(link) 
    107     return os.path.sep.join(hook_file.split(os.path.sep)[:-2]) 
    10898 
    109 def get_trac_path(link): 
    110     """ 
    111     This function determines the target of a symlink. 
    112      
    113     @return: String 
    114     @param link: String 
    115     """ 
    116     hook_file= os.readlink(link) 
    117     return os.path.sep.join(hook_file.split(os.path.sep)[:-2]) 
    11899 
    119100def run_trac_advanced(settings, repos, rev): 
  • tracsvnpoliciesplugin/0.11/svnpolicies/hooks/pre-revprop-change.py

    r3124 r3135  
    5858     
    5959    return False 
    60  
    61 def get_trac_path(link): 
    62     """ 
    63     This function determines the target of a symlink. 
    64      
    65     @return: String 
    66     @param link: String 
    67     """ 
    68     hook_file= os.readlink(link) 
    69     return os.path.sep.join(hook_file.split(os.path.sep)[:-2]) 
    7060 
    7161if __name__ == "__main__": 
  • tracsvnpoliciesplugin/0.11/svnpolicies/svnpolicy.conf

    r3124 r3135  
    1 PYTHON_SITE_DIR="/var/trac-0.11-dev/lib/python2.4/site-packages/"; 
    2 #PYTHON_SITE_DIR="/usr/local/lib/python2.4/site-packages/"; 
    31TRAC_CODE_PATH="/home/oforge/code/trac/trunk/vendor/trac-0.11dev"; 
    4 #TRAC_CODE_PATH="/etf/trunk/vendor/trac-0.11dev"; 
    52AUTHOR_URL_TEMPLATE= "https://intranet.optaros.com/user/%s"; 
    63CHANGESET_URL= "https://projects.optaros.com/trac/%s/changeset/%s";