diff options
author | Auke Booij (tulcod) <auke@tulcod.com> | 2010-08-01 13:49:29 +0200 |
---|---|---|
committer | Auke Booij (tulcod) <auke@tulcod.com> | 2010-08-01 13:49:29 +0200 |
commit | 327df2d2177065070f8ac4d02f9dd6e43adf00f9 (patch) | |
tree | 62a169959a7aea72cc917fca37c3389e0e118f00 | |
parent | I present to you: external dependencies, woohoo! (diff) | |
parent | Add support for generating manifests (diff) | |
download | g-cran-327df2d2177065070f8ac4d02f9dd6e43adf00f9.tar.gz g-cran-327df2d2177065070f8ac4d02f9dd6e43adf00f9.tar.bz2 g-cran-327df2d2177065070f8ac4d02f9dd6e43adf00f9.zip |
Merge branch 'gcommon'
-rwxr-xr-x | bin/g-common | 6 | ||||
-rw-r--r-- | g_common/__init__.py | 0 | ||||
-rwxr-xr-x | g_common/common.ebuild (renamed from g_cran/cran.ebuild) | 6 | ||||
-rw-r--r-- | g_common/g_common.py | 172 | ||||
-rw-r--r-- | g_common/gcommon.eclass | 32 | ||||
-rw-r--r-- | g_common/settings.py | 5 | ||||
-rw-r--r-- | g_cran/cran.cfg | 1 | ||||
-rw-r--r-- | g_cran/g_cran.py | 13 | ||||
-rw-r--r-- | setup.py | 11 |
9 files changed, 227 insertions, 19 deletions
diff --git a/bin/g-common b/bin/g-common new file mode 100755 index 0000000..e2649a4 --- /dev/null +++ b/bin/g-common @@ -0,0 +1,6 @@ +#!python +from g_common import g_common + +if __name__ == "__main__": + g_common.main() + diff --git a/g_common/__init__.py b/g_common/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/g_common/__init__.py diff --git a/g_cran/cran.ebuild b/g_common/common.ebuild index ac4d286..1904c57 100755 --- a/g_cran/cran.ebuild +++ b/g_common/common.ebuild @@ -10,12 +10,12 @@ this_repo="${this_dirname}/../../" #discover category, package name and version cat_pn_pvr=$(echo $this_file|/bin/sed -r 's$.+?/([A-Za-z0-9+_.-]+)/([A-Za-z0-9+_-]+)/\2-([0-9]+(\.[0-9]+)*[a-z]?((_alpha|_beta|_pre|_rc|_p)[0-9]*)*(-r[0-9]*)?)\.ebuild$\1/\2 \3$') -#this reads in metadata from g-cran +#this reads in metadata from g-common { while read -r line do export "$line" done -} < <(/usr/bin/g-cran $this_repo package $cat_pn_pvr || die); +} < <(/usr/bin/g-common $this_repo package $cat_pn_pvr || die); for phase in $GCOMMON_PHASES do @@ -23,5 +23,5 @@ do done function exec_phase() { - /usr/bin/g-cran $this_repo $1 || die + /usr/bin/g-common $this_repo $1 || die } diff --git a/g_common/g_common.py b/g_common/g_common.py new file mode 100644 index 0000000..90fecfa --- /dev/null +++ b/g_common/g_common.py @@ -0,0 +1,172 @@ +#!/usr/bin/python +import getopt, sys, os, string, urllib, re, subprocess +import settings + +#__doc__="Usage: "+sys.argv[0]+" <local repository directory> <action> [<action arguments>...]" + +def verbose_system(command): + print command + return os.system(command) + +def list_configured_drivers(): + #all .cfg files which end in .cfg as they should + return [x[:-len('.cfg')] for x in os.listdir(settings.GLOBAL_CONF_DIR) if x[-len('.cfg'):]=='.cfg'] + +#read key=value file to dict +def read_config(conf_file,defaults={}): + conffile=open(conf_file) + conf=defaults.copy() + for line in conffile: + if len(line): + value=line[line.find("=")+1:] + if value[-1]=='\n': + value=value[:-1] + conf[line[:line.find("=")]]=value + + return conf + +#returns dict of key=value config file +def read_driver_config(driver_name): + conffile=os.path.join(settings.GLOBAL_CONF_DIR,settings.DRIVER_DIR,driver_name+'.cfg') + return read_config(conffile,{ + #'name':None, + #'executable':None, + }) + return configs #dict + +#read g-common config for a repo +def read_repo_config(repo_location): + hidden_conffile=os.path.join(repo_location,settings.MYDIR,'repo.cfg') + return read_config(hidden_conffile) + +#sync a local repository's PACKAGES file +def action_sync(repo_location,driver,remote_uri): + if driver==None: + repo_conf=read_repo_config(repo_location) + driver=repo_conf['driver'] + driver_conf=read_driver_config(driver) + + if remote_uri is None: + remote_uri=repo_conf['uri'] + + if os.path.exists(repo_location): + try: + os.makedirs(os.path.join(repo_location,settings.MYDIR)) + except: + pass + cfg_file=open(os.path.join(repo_location,settings.MYDIR,"repo.cfg"),"w") + cfg_file.write('driver='+driver+'\n') + cfg_file.write('uri='+remote_uri+'\n') + cfg_file.close() + + return verbose_system(driver_conf['exec']+" "+repo_location+" sync "+remote_uri) + +#list categories in this repositorie +def list_categories(repo_location): + repo_conf=read_repo_config(repo_location) + driver_conf=read_driver_config(repo_conf['driver']) + + if remote_uri is None: + remote_uri=repo_conf['uri'] + + return verbose_system(driver_conf['exec']+" "+repo_location+" list-categories") + +#idem ditto +def list_packages(repo_location): + repo_conf=read_repo_config(repo_location) + driver_conf=read_driver_config(repo_conf['driver']) + + if remote_uri is None: + remote_uri=repo_conf['uri'] + + return verbose_system(driver_conf['exec']+" "+repo_location+" list-packages") + + +#generate a tree of ebuilds... note that we only link ebuild files, instead of generating them +#we will, however, generate metadata.xml and Manifest files +def generate_tree(repo_location): + repo_conf=read_repo_config(repo_location) + driver_conf=read_driver_config(repo_conf['driver']) + + ebuild_file=settings.COMMON_EBUILD_FILE #get from settings + import hashlib + ebuild_digest=hashlib.sha1(open(ebuild_file).read()).hexdigest() + Manifest="EBUILD %s SHA1 "+ebuild_digest + + packages_list_pipe=subprocess.Popen(driver_conf['exec']+' '+repo_location+' list-packages',shell=True,stdout=subprocess.PIPE) + os.waitpid(packages_list_pipe.pid,0) + for line in packages_list_pipe.stdout: + category=line[:line.find("/")] + package=line[line.find("/")+1:line.find(" ")] + version=line[line.find(" ")+1:-1] + ebuild_dir=os.path.join(repo_location,category,package) + if not os.path.exists(ebuild_dir): + os.makedirs(ebuild_dir) + package_file=package+'-'+version+'.ebuild' + os.symlink(ebuild_file,os.path.join(ebuild_dir,package_file)) + manifest_file=open(os.path.join(ebuild_dir,'Manifest'),"w") + manifest_file.write(Manifest % package_file) + +#list package details, in PMS's format +def action_package(repo_location,package_name): + repo_conf=read_repo_config(repo_location) + driver_conf=read_driver_config(repo_conf['driver']) + + if remote_uri is None: + remote_uri=repo_conf['uri'] + + return verbose_system(driver_conf['exec']+" "+repo_location+" package "+package_name) + +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)<2 or 'help' in arguments: + print "The 'sync' action takes the following parameters:" + print " * [driver]" + print " * [remote_repository_uri]" + sys.exit(1) + driver=None + remote_repo=None + if len(arguments)>2: + driver=arguments[2] + if len(arguments)>3: + remote_repo=arguments[3] + action_sync(repo_location,driver,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 or 'help' in arguments: + 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' or action=='help': + usage() + elif action in pms_phases: + #todo + raise NotImplementedError + elif action in actions_wanted: + raise NotImplementedError + else: + usage() + sys.exit(0) + +if __name__ == "__main__": + main() + + diff --git a/g_common/gcommon.eclass b/g_common/gcommon.eclass new file mode 100644 index 0000000..b1b7bd3 --- /dev/null +++ b/g_common/gcommon.eclass @@ -0,0 +1,32 @@ +# Copyright 1999-2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +# +# Original Author: Auke Booij +# Purpose: g-common compatibility layer for package managers without native +# support for g-common-capable non-ebuild repository drivers +# + +this_dirname=$(/bin/dirname ${BASH_ARGV[0]}) +this_repo="${this_dirname}/../../" + +#discover category, package name and version +cat_pn_pvr=$(echo $this_file|/bin/sed -r 's$.+?/([A-Za-z0-9+_.-]+)/([A-Za-z0-9+_-]+)/\2-([0-9]+(\.[0-9]+)*[a-z]?((_alpha|_beta|_pre|_rc|_p)[0-9]*)*(-r[0-9]*)?)\.ebuild$\1/\2 \3$') + +#this reads in metadata from g-cran +{ while read -r line +do + export "$line" +done +} < <(/usr/bin/g-common $this_repo package $cat_pn_pvr || die); + +for phase in $GCOMMON_PHASES +do + eval "$(printf '%q() { exec_phase %q; }' "$phase" "$phase")" +done + +function exec_phase() { + /usr/bin/g-common $this_repo $1 || die +} + diff --git a/g_common/settings.py b/g_common/settings.py new file mode 100644 index 0000000..5163c2f --- /dev/null +++ b/g_common/settings.py @@ -0,0 +1,5 @@ +GLOBAL_CONF_DIR='/usr/share/g-common/' +DRIVER_DIR='drivers/' +COMMON_EBUILD_FILE=GLOBAL_CONF_DIR+'common.ebuild' +MYDIR='.g-common' + diff --git a/g_cran/cran.cfg b/g_cran/cran.cfg new file mode 100644 index 0000000..31b90d6 --- /dev/null +++ b/g_cran/cran.cfg @@ -0,0 +1 @@ +exec=/usr/bin/g-cran diff --git a/g_cran/g_cran.py b/g_cran/g_cran.py index 6898109..d005d38 100644 --- a/g_cran/g_cran.py +++ b/g_cran/g_cran.py @@ -35,17 +35,6 @@ def list_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=[] @@ -90,8 +79,6 @@ def main(): 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:" @@ -8,7 +8,12 @@ setup(name='G-CRAN', author='Auke Booij (tulcod)', author_email='auke@tulcod.com', url='http://git.overlays.gentoo.org/gitweb/?p=proj/g-cran.git ', - packages=['g_cran'], - scripts=['bin/g-cran'], - package_data={'g_cran':['cran.ebuild','convert_packages_rds.R']}, + packages=['g_cran','g_common'], + scripts=['bin/g-cran','bin/g-common'], + package_data={'g_cran':['convert_packages_rds.R']}, + data_files=[ + #('/etc/g-common/',['g_common/']), + ('/usr/share/g-common/drivers/',['g_cran/cran.cfg']), + ('/usr/share/g-common/',['g_common/common.ebuild']), + ] ) |