summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAuke Booij (tulcod) <auke@tulcod.com>2010-06-30 13:44:49 +0200
committerAuke Booij (tulcod) <auke@tulcod.com>2010-07-04 00:09:36 +0200
commitf2b03d2ef2f29fc8959aaaddd29f6954d055fe4b (patch)
treeeca5167a78d2648d12175474bb6fcc168c8db7ce
parentDon't process empty package data (diff)
downloadg-cran-f2b03d2ef2f29fc8959aaaddd29f6954d055fe4b.tar.gz
g-cran-f2b03d2ef2f29fc8959aaaddd29f6954d055fe4b.tar.bz2
g-cran-f2b03d2ef2f29fc8959aaaddd29f6954d055fe4b.zip
When a dependency package name can be found in portage, then it's used
as a qualified package name
-rw-r--r--g_cran/cran_read.py80
-rw-r--r--g_cran/g_cran.py3
2 files changed, 55 insertions, 28 deletions
diff --git a/g_cran/cran_read.py b/g_cran/cran_read.py
index aeb1867..4e45abc 100644
--- a/g_cran/cran_read.py
+++ b/g_cran/cran_read.py
@@ -25,6 +25,23 @@ def portage_dir():
raise RuntimeError('Could not deduce portage location')
return portage_location
+#list packages in the portage tree
+def portage_possible_deps(_portage_packages={}):
+ if len(_portage_packages): return _portage_packages
+ portdir=portage_dir()
+ categories_file=open(os.path.join(portdir,'profiles','categories'))
+ categories=[x.strip() for x in categories_file.readlines()]
+ for category in categories:
+ packages=[x for x in os.listdir(os.path.join(portdir,category)) if
+ os.path.isdir(os.path.join(portdir,category,x)) and x[0]!='.'] #exclude hidden dirs
+ for package in packages:
+ if package in _portage_packages: #already added, add to list
+ _portage_packages[package].append(category+'/'+package)
+ else:
+ _portage_packages[package]=[category+'/'+package,]
+ return _portage_packages
+
+
def pmsify_license_field(license_list):
portdir=portage_dir()
available_licenses=os.listdir(os.path.join(portdir,'licenses'))
@@ -53,7 +70,7 @@ def pmsify_license_field(license_list):
def pmsify_package_name(name):
if len(name)==0:
- return 'test'
+ raise RuntimeError('Empty package name')
name=re.sub('[^a-zA-Z0-9+_-]','',name) #name may only contain these characters
if not re.match('[a-zA-Z0-9+_].*',name): #package name must start with [a-zA-Z0-9+_]
name='_'+name
@@ -64,45 +81,47 @@ def pmsify_package_name(name):
def pmsify_package_version(version_str):
return version_str.replace('-','.') #some CRAN-style versions have the form 0.1-1, which we transform into 0.1.1
-def pmsify_package_list(package_list):
- #note: the following returns a list of tuples
- matches=re.findall(r'\s*(([^,]+\([^()]+?\))|([^,]+))\s*',package_list) #split into packages + versions
+def listify_package_list(package_list):
+ matches=re.findall(r'\s*([^,)(]+?)\s*(\([^()]+?\))?\s*([,)(]|$)',package_list) #split into packages + versions
packages=[]
for package_part in matches: #process each package match
- if len(package_part[1])>len(package_part[2]): #versioned package identifier
- parse=re.match(r'([^,]+)\(([^()]+?)\)',package_part[1])
- pkg_name=parse.group(1).strip()
- versions=parse.group(2)
- #fixme version specifiers
- if pkg_name=='R':
- category='dev-lang'
- else:
- category='dev-R'
- packages.append(category+'/'+pkg_name)
- else:
- pkg_name=package_part[2].strip()
- if pkg_name=='R':
- category='dev-lang'
- else:
- category='dev-R' #assume it's a CRAN package
- packages.append(category+'/'+pkg_name)
+ #package_part[0] is package name
+ #package_part[1] is package version matcher
+ if len(package_part[0]): #if we see a package name
+ packages.append(package_part[0])
return packages
+def pmsify_package_list(package_list, cran_packages):
+ #note: the following returns a list of tuples
+ pms_packages=[]
+ portage_packages=portage_possible_deps()
+ for package in package_list:
+ if package in cran_packages:
+ pms_packages.append('dev-R/'+pmsify_package_name(package))
+ elif package in portage_packages:
+ pms_packages.append(portage_packages[package][0]) #get qualified package name from the portage tree
+ else: #fallback to dev-R and assume it's in another R package repository
+ pms_packages.append('dev-R/'+pmsify_package_name(package))
+ return pms_packages
+
#Parse package options into values we can work with in accordance with PMS
def pmsify_package_data(data,remote_repository):
pms_pkg=Ebuild()
pms_pkg.cran_data=data
e_vars=pms_pkg.ebuild_vars
#fix settings:
+ if 'package' not in data:
+ print data
+ raise RuntimeError("No package name")
e_vars['pn']=pmsify_package_name(data['package'])
if 'version' not in data: #set a version even if we have none
e_vars['pv']='0'
else:
e_vars['pv']=pmsify_package_version(data['version'])
if 'depends' in data:
- deps=pmsify_package_list(data['depends'])
+ deps=listify_package_list(data['depends'])
else: #some packages don't set dependencies, so force dependency on R
- deps=['dev-lang/R',]
+ deps=['R',]
e_vars['depend']=deps
e_vars['pdepend']=deps
e_vars['rdepend']=deps
@@ -119,19 +138,28 @@ def pmsify_package_data(data,remote_repository):
e_vars['src_uri']=remote_repository+'/src/contrib/'+data['package']+'_'+data['version']+'.tar.gz'
return pms_pkg
+#read sync'ed CRAN data into RAM to PMS-style packages
def read_packages(package_filename,local_repository):
packages_file=open(package_filename,"r")
file_parts=EmptyLinesFile(packages_file) #this is where we split the PACKAGES file into several file parts
- packages=[]
+ packages={}
import rfc822
repository_file=open(os.path.join(local_repository,REPO_MYDIR,'remote_uri'),'r')
remote_uri=repository_file.read().strip()
+ #read PACKAGES file
while not file_parts.eof:
cran_package=dict(rfc822.Message(file_parts).items()) #read part of PACKAGES file
if len(cran_package):
pms_package=pmsify_package_data(cran_package,remote_uri) #fix values
- packages.append(pms_package) #store in dict
- return packages
+ packages[pms_package.cran_data['package']]=pms_package #store in dict
+ #post-process dependency data, transform to qualified package names
+ cran_packages=packages.keys()
+ for cran_name, package in packages.iteritems():
+ deps=pmsify_package_list(package.ebuild_vars['depend'],cran_packages)
+ package.ebuild_vars['depend']=deps
+ package.ebuild_vars['rdepend']=deps
+ package.ebuild_vars['pdepend']=deps
+ return packages.values()
def find_package(repo_location,package_name):
packages=read_packages(os.path.join(repo_location,REPO_MYDIR,'PACKAGES'),repo_location)
diff --git a/g_cran/g_cran.py b/g_cran/g_cran.py
index 0a071b0..69dddee 100644
--- a/g_cran/g_cran.py
+++ b/g_cran/g_cran.py
@@ -9,8 +9,7 @@ __doc__="Usage: "+sys.argv[0]+" <local repository directory> <action> [<action a
def action_sync(repo_location,remote_uri):
if not os.path.isdir(os.path.join(repo_location, REPO_MYDIR)):
- if os.path.isdir(repo_location):
- os.mkdir(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')