From 15723e7e1fc380d0d119a915965c9065277e15a0 Mon Sep 17 00:00:00 2001 From: "Auke Booij (tulcod)" Date: Thu, 15 Jul 2010 15:37:48 +0200 Subject: Start development of g-common --- bin/g-common | 6 +++ g_common/__init__.py | 0 g_common/g_common.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ g_common/gcommon.eclass | 32 ++++++++++++++ g_common/settings.py | 1 + setup.py | 4 +- 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100755 bin/g-common create mode 100644 g_common/__init__.py create mode 100644 g_common/g_common.py create mode 100644 g_common/gcommon.eclass create mode 100644 g_common/settings.py 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 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]+" [...]" + +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() + + 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..3fb5118 --- /dev/null +++ b/g_common/settings.py @@ -0,0 +1 @@ +GLOBAL_CONF_DIR='/etc/g-common/' diff --git a/setup.py b/setup.py index 69e8228..e38682e 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ 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'], + packages=['g_cran','g_common'], + scripts=['bin/g-cran','bin/g-common'], package_data={'g_cran':['cran.ebuild','convert_packages_rds.R']}, ) -- cgit v1.2.3-65-gdbad