diff options
Diffstat (limited to 'g_common/g_common.py')
-rw-r--r-- | g_common/g_common.py | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/g_common/g_common.py b/g_common/g_common.py new file mode 100644 index 0000000..c5c1120 --- /dev/null +++ b/g_common/g_common.py @@ -0,0 +1,110 @@ +#!/usr/bin/python +import getopt, sys, os, string, urllib, re +import settings + +#__doc__="Usage: "+sys.argv[0]+" <local repository directory> <action> [<action arguments>...]" + +def list_configured_drivers(): + return [os.listdir(settings.GLOBAL_CONF_DIR)] + +def read_driver_config(driver_name): + + +#sync a local repository's PACKAGES file +def action_sync(repo_location,remote_uri): + if not os.path.isdir(os.path.join(repo_location, REPO_MYDIR)): + os.mkdir(os.path.join(repo_location,REPO_MYDIR)) + packages_filename=os.path.join(repo_location, REPO_MYDIR, 'PACKAGES') + urllib.urlretrieve(remote_uri+'/src/contrib/PACKAGES',packages_filename) + repo_file=open(os.path.join(repo_location,REPO_MYDIR,'remote_uri'),'w') + repo_file.write(remote_uri) + +#list categories in this repositorie +def list_categories(repo_location): + print "dev-R" + +#idem ditto +def list_packages(repo_location): + packages=read_packages(os.path.join(repo_location,REPO_MYDIR,'PACKAGES'),repo_location) + for package in packages: + print 'dev-R/'+package.ebuild_vars['pn'],package.ebuild_vars['pv'] + +#generate a tree of ebuilds... note that we only link ebuild files +#metadata.xml and Manifest and whatnot is not generated +def generate_tree(repo_location): + packages=read_packages(os.path.join(repo_location,REPO_MYDIR,'PACKAGES'),repo_location) + ebuild_file=os.path.join(os.path.dirname(__file__),'cran.ebuild') + for package in packages: + ebuild_dir=os.path.join(repo_location,'dev-R',package.ebuild_vars['pn']) + if not os.path.exists(ebuild_dir): + os.makedirs(ebuild_dir) + os.symlink(ebuild_file,os.path.join(ebuild_dir,package.ebuild_vars['pn']+'-'+package.ebuild_vars['pv']+'.ebuild')) + +#list package details, in PMS's format +def action_package(repo_location,package_name): + defined_phases=[] + package=find_package(repo_location,package_name[package_name.find('/')+1:]) + #output data + for key,value in package.ebuild_vars.iteritems(): + if key=='pn' or key=='pv': #readonly vars, we cannot set these in ebuilds + pass + elif isinstance(value,str): #if string + print key.upper()+'='+value.replace('\n','') + elif isinstance(value,list) and key=='license': + if len(value)>1: + print "LICENSE=|| ( "+' '.join(value)+' )' + else: + print "LICENSE="+' '.join(value) + elif isinstance(value,list): #list, concat items + print key.upper()+'='+' '.join(value).replace('\n','') + for pms_func in pms_phases: + if hasattr(phases,pms_func): + defined_phases.append(pms_func) + print 'GCOMMON_PHASES='+' '.join(defined_phases) + +def usage(): + print __doc__ + +def main(): + arguments=sys.argv[1:] + #print options, arguments + if len(arguments)<2: #we need at least a local repository location and an action + usage() + sys.exit(0) + action=arguments[1] + repo_location=os.path.abspath(arguments[0]) + if action=='sync': + if len(arguments)<3: + print "The 'sync' action takes the following parameters:" + print " * remote_repository_uri" + sys.exit(1) + remote_repo=arguments[2] + action_sync(repo_location,remote_repo) + elif action=='list-categories': + list_categories(repo_location) + elif action=='list-packages': + list_packages(repo_location) + elif action=='generate-tree': + generate_tree(repo_location) + elif action=='package': + if len(arguments)<3: + print "The 'package' action takes the following parameters:" + print " * category/package_name" + print " * [version]" + sys.exit(1) + package_name=arguments[2] + action_package(repo_location,package_name) + elif action=='usage': + usage() + elif action in pms_phases and hasattr(phases,action): + getattr(phases,action)(os.environ,repo_location) + elif action in actions_wanted: + raise NotImplementedError + else: + usage() + sys.exit(0) + +if __name__ == "__main__": + main() + + |