Changeset 3135
- Timestamp:
- 01/23/08 09:53:42 (1 year ago)
- Files:
-
- tracsvnpoliciesplugin/0.11/svnpolicies/api.py (modified) (3 diffs)
- tracsvnpoliciesplugin/0.11/svnpolicies/hooks/loader.py (modified) (1 diff)
- tracsvnpoliciesplugin/0.11/svnpolicies/hooks/post-commit.py (modified) (2 diffs)
- tracsvnpoliciesplugin/0.11/svnpolicies/hooks/pre-commit.py (modified) (1 diff)
- tracsvnpoliciesplugin/0.11/svnpolicies/hooks/pre-revprop-change.py (modified) (1 diff)
- tracsvnpoliciesplugin/0.11/svnpolicies/svnpolicy.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracsvnpoliciesplugin/0.11/svnpolicies/api.py
r3125 r3135 1 1 # -*- coding: utf-8 -*- 2 2 # 3 4 3 5 4 … … 9 8 from pkg_resources import Requirement, resource_string, resource_filename 10 9 11 all= ['IniReader', 'validate_email', 'get_global_configurations', 'get_resource_path', 'get_hook_path'] 10 all= ['IniReader', 11 'validate_email', 12 'get_global_configurations', 13 'get_resource_path', 14 'get_hook_path', 15 'get_site_packages'] 16 17 def get_site_packages(): 18 return path.sep.join(__file__.split(path.sep)[:-3]) 12 19 13 20 def validate_email(email): … … 53 60 """ 54 61 """ 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 57 75 # return the resource name 58 76 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 2 import os 2 3 3 4 _variables = None 4 5 5 def get_ global_configurations(variable_name=None):6 def get_real_path(link, cut_by=2): 6 7 """ 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. 9 9 10 @param variable_name: String 10 @return: String 11 @param link: String 11 12 """ 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]) 29 15 16 def 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]) 30 25 31 production= True 26 PYTHONPATH = '' 27 production= False 32 28 try : 33 29 from svnpolicies import api 34 30 except Exception : 35 31 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) 37 38 production= True 38 39 from svnpolicies import api 39 40 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" + \41 AUTHOR_URL_TEMPLATE = api.get_global_configurations('AUTHOR_URL_TEMPLATE'); 42 CHANGESET_URL = api.get_global_configurations('CHANGESET_URL'); 43 SVNNOTIFY = api.get_global_configurations('SVNNOTIFY'); 44 SVNLOOK = api.get_global_configurations('SVNLOOK'); 45 SMTP_HOST = api.get_global_configurations('SMTP_HOST'); 46 SMTP_USER = api.get_global_configurations('SMTP_USER'); 47 SMTP_PASSWORD = api.get_global_configurations('SMTP_PASSWORD'); 48 CREDENTIALS = "-S" + \ 48 49 " --smtp " + SMTP_HOST + \ 49 50 " --smtp-user " + SMTP_USER + \ 50 51 " --smtp-password " + SMTP_PASSWORD 51 52 52 PYTHONPATH= get_global_configurations('PYTHON_SITE_DIR') 53 TRAC_CODE_PATH = api.get_global_configurations('TRAC_CODE_PATH'); 53 54 54 TRAC_CODE_PATH=get_global_configurations('TRAC_CODE_PATH');55 tracsvnpoliciesplugin/0.11/svnpolicies/hooks/post-commit.py
r3124 r3135 22 22 if PYTHONPATH != "" and production: 23 23 prefix= "export \"PYTHONPATH=%s\"; \n" % PYTHONPATH 24 24 print prefix 25 25 p = subprocess.Popen(prefix + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 26 26 out_text= p.stdout.readlines() … … 94 94 "-U", CHANGESET_URL % (project_name, '%s')]) 95 95 return command 96 97 def get_trac_path(link):98 """99 This function determines the target of a symlink.100 101 @return: String102 @param link: String103 """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: String112 @param link: String113 """114 hook_file= os.path.realpath(link)115 return os.path.sep.join(hook_file.split(os.path.sep)[:-2])116 96 117 97 tracsvnpoliciesplugin/0.11/svnpolicies/hooks/pre-commit.py
r3124 r3135 96 96 return False 97 97 return True 98 99 def get_real_path(link):100 """101 This function determines the real file that hides under symlinks.102 103 @return: String104 @param link: String105 """106 hook_file= os.path.realpath(link)107 return os.path.sep.join(hook_file.split(os.path.sep)[:-2])108 98 109 def get_trac_path(link):110 """111 This function determines the target of a symlink.112 113 @return: String114 @param link: String115 """116 hook_file= os.readlink(link)117 return os.path.sep.join(hook_file.split(os.path.sep)[:-2])118 99 119 100 def run_trac_advanced(settings, repos, rev): tracsvnpoliciesplugin/0.11/svnpolicies/hooks/pre-revprop-change.py
r3124 r3135 58 58 59 59 return False 60 61 def get_trac_path(link):62 """63 This function determines the target of a symlink.64 65 @return: String66 @param link: String67 """68 hook_file= os.readlink(link)69 return os.path.sep.join(hook_file.split(os.path.sep)[:-2])70 60 71 61 if __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/";3 1 TRAC_CODE_PATH="/home/oforge/code/trac/trunk/vendor/trac-0.11dev"; 4 #TRAC_CODE_PATH="/etf/trunk/vendor/trac-0.11dev";5 2 AUTHOR_URL_TEMPLATE= "https://intranet.optaros.com/user/%s"; 6 3 CHANGESET_URL= "https://projects.optaros.com/trac/%s/changeset/%s";
