diff options
author | 2010-08-01 22:13:52 +0200 | |
---|---|---|
committer | 2010-08-01 23:20:15 +0200 | |
commit | b35af36c1ea7a10c76af0a5e880b91946f5c0e1f (patch) | |
tree | 0dc279ced6a44441afed6a16b4f7b588b402cc3b | |
parent | Conditional metadata+manifest generation (diff) | |
download | g-cran-b35af36c1ea7a10c76af0a5e880b91946f5c0e1f.tar.gz g-cran-b35af36c1ea7a10c76af0a5e880b91946f5c0e1f.tar.bz2 g-cran-b35af36c1ea7a10c76af0a5e880b91946f5c0e1f.zip |
Fixes; write local package database
-rw-r--r-- | g_cran/cran_read.py | 23 | ||||
-rw-r--r-- | g_cran/g_cran.py | 50 | ||||
-rw-r--r-- | g_cran/phases.py | 4 |
3 files changed, 60 insertions, 17 deletions
diff --git a/g_cran/cran_read.py b/g_cran/cran_read.py index 0906ec9..f648830 100644 --- a/g_cran/cran_read.py +++ b/g_cran/cran_read.py @@ -1,4 +1,4 @@ -import re, os +import re, os, tarfile, rfc822 from ebuild import * from filetricks import * from settings import * @@ -194,8 +194,19 @@ def read_packages(package_filename,local_repository): #find a package in this repository... we really should cache this #into some sqlite database once def find_package(repo_location,package_name): - packages=read_packages(os.path.join(repo_location,REPO_MYDIR,'PACKAGES'),repo_location) - for package in packages: - if package.ebuild_vars['pn']==package_name: - return package - raise ValueError("Package not found") + database_tarball=tarfile.open(os.path.join(repo_location,REPO_MYDIR,'database.tgz'),'r') + package_file=database_tarball.extractfile(package_name) + if package_file==None: + raise DoesNotExist + + repository_file=open(os.path.join(repo_location,REPO_MYDIR,'remote_uri'),'r') + remote_uri=repository_file.read().strip() + + pms_package=pmsify_package_data(dict(rfc822.Message(package_file).items()),remote_uri) + return pms_package + + #packages=read_packages(os.path.join(repo_location,REPO_MYDIR,'PACKAGES'),repo_location) + #for package in packages: + # if package.ebuild_vars['pn']==package_name: + # return package + #raise ValueError("Package not found") diff --git a/g_cran/g_cran.py b/g_cran/g_cran.py index d005d38..9a7a347 100644 --- a/g_cran/g_cran.py +++ b/g_cran/g_cran.py @@ -1,8 +1,9 @@ #!/usr/bin/python -import getopt, sys, os, string, urllib, re +import getopt, sys, os, string, urllib, re, tarfile, StringIO from ebuild import * import phases from cran_read import * +from filetricks import * from settings import * __doc__="Usage: "+sys.argv[0]+" <local repository directory> <action> [<action arguments>...]" @@ -24,16 +25,44 @@ def action_sync(repo_location,remote_uri): 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) + repo_file.close() + + import rfc822 + packages_file=open(packages_filename,"r") + file_parts=EmptyLinesFile(packages_file) + database_tarball=tarfile.open(os.path.join(repo_location,REPO_MYDIR,'database.tgz'),'w:gz') + #read PACKAGES file + while not file_parts.eof: + current_package='' + while True: + line=file_parts.readline() + if len(line.strip()): #nonempty line, add to current_package + current_package=current_package+line + else: + break + rfc822_file=StringIO.StringIO(current_package) + cran_package=dict(rfc822.Message(rfc822_file).items()) #read part of PACKAGES file + if len(cran_package): + pms_package=pmsify_package_data(cran_package,remote_uri) #fix values + #now add the package to the database tarball + file_contents=StringIO.StringIO(current_package) + new_tar_file=tarfile.TarInfo(name=pms_package.ebuild_vars['pn']) + new_tar_file.size=len(file_contents.buf) + database_tarball.addfile(tarinfo=new_tar_file,fileobj=file_contents) + database_tarball.close() + return 0 #list categories in this repository def list_categories(repo_location): print "dev-R" + return 0 #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'] + return 0 #list package details, in PMS's format def action_package(repo_location,package_name): @@ -56,9 +85,11 @@ def action_package(repo_location,package_name): if hasattr(phases,pms_func): defined_phases.append(pms_func) print 'GCOMMON_PHASES='+' '.join(defined_phases) + return 0 def usage(): print __doc__ + return 0 def main(): arguments=sys.argv[1:] @@ -74,11 +105,11 @@ def main(): print " * remote_repository_uri" sys.exit(1) remote_repo=arguments[2] - action_sync(repo_location,remote_repo) + return action_sync(repo_location,remote_repo) elif action=='list-categories': - list_categories(repo_location) + return list_categories(repo_location) elif action=='list-packages': - list_packages(repo_location) + return list_packages(repo_location) elif action=='package': if len(arguments)<3: print "The 'package' action takes the following parameters:" @@ -86,18 +117,17 @@ def main(): print " * [version]" sys.exit(1) package_name=arguments[2] - action_package(repo_location,package_name) + return action_package(repo_location,package_name) elif action=='usage': - usage() + return usage() elif action in pms_phases and hasattr(phases,action): - getattr(phases,action)(os.environ,repo_location) + return getattr(phases,action)(os.environ,repo_location) elif action in actions_wanted: raise NotImplementedError else: - usage() - sys.exit(0) + return usage() if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/g_cran/phases.py b/g_cran/phases.py index 59dd683..17e78d1 100644 --- a/g_cran/phases.py +++ b/g_cran/phases.py @@ -9,7 +9,7 @@ def verbose_system(command): #no need to unpack, see src_compile def pkg_unpack(env,local_repository): - pass + return 0 #This function actually creates a binary package (a tarball) from the source package #this way, we cleanly split up R package installing into a compile and install phase @@ -24,6 +24,7 @@ def src_compile(env,local_repository): returnval=verbose_system("R CMD INSTALL --build "+tarball+" -l "+tmp_target) if returnval: raise RuntimeError("R build failed") + return 0 def src_install(env,local_repository): package=cran_read.find_package(local_repository,env['PN']) @@ -63,5 +64,6 @@ def src_install(env,local_repository): #not implemented else: shutil.rmtree(os.path.join(r_library,package.cran_data['package'],'html')) + return 0 |