From 7ec3dd558d1cf598b924eda885e05d21c75abefa Mon Sep 17 00:00:00 2001 From: "Auke Booij (tulcod)" Date: Sat, 26 Jun 2010 21:42:50 +0200 Subject: Fix license parsing --- g_cran/cran_read.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- g_cran/g_cran.py | 6 ++++-- 2 files changed, 52 insertions(+), 3 deletions(-) (limited to 'g_cran') diff --git a/g_cran/cran_read.py b/g_cran/cran_read.py index ea5904a..768712c 100644 --- a/g_cran/cran_read.py +++ b/g_cran/cran_read.py @@ -3,6 +3,53 @@ from ebuild import * from filetricks import * from settings import * +#figure out the location of the portage tree, or return it if we already know it +portage_location=None +def portage_dir(): + global portage_location + if portage_location!=None: #we already know + return portage_location + if os.path.exists('/etc/paludis/repositories/gentoo.conf'): #paludis stores repository data here + conffile=open('/etc/paludis/repositories/gentoo.conf') + for line in conffile: + if 'location'==line[:len('location')]: + portage_location=re.sub('\$\{.+?\}','',line[line.find('=')+1:]).strip() #remove ${ROOT} and other variables (lucky guess, lol) + elif os.path.exists('/etc/make.conf'): #portage stores portage location here + conffile=open('/etc/make.conf') + for line in conffile: + if 'PORTDIR' in line and '=' in line: + portage_location=re.sub('\"(.*)\"','\1',line[line.find('='):]).strip() + elif os.path.exists('/usr/portage'): #default location + portage_location='/usr/portage' + else: + raise RuntimeError('Could not deduce portage location') + return portage_location + +def pmsify_license_field(license_list): + portdir=portage_dir() + available_licenses=os.listdir(os.path.join(portdir,'licenses')) + #note: the following returns a list of tuples + matches=re.findall(r'\s*([^|]+)\s*',license_list) #split into licenses + versions + licenses=[] + for license_part in matches: #process each license option + if license_part[:4]=='file': #license field referse to a file + #licenses.append(license_part) #we'll have to somehow install this file... + continue + parse=re.match(r'(.+)\(\W*([^()]+?)\)',license_part) + try_license=None + if parse: #versioned license + license_name=parse.group(1).strip() + version=parse.group(2).strip() + try_license=license_name+'-'+version + for license in available_licenses: + if license==license_part or try_license==license: + licenses.append(license) + found_license=True + break + else: + licenses.append('as-is') #unknown + return licenses + def pmsify_package_name(name): if len(name)==0: return 'test' @@ -66,7 +113,7 @@ def pmsify_package_data(data,remote_repository): else: e_vars['description']=e_vars['pn'] if 'license' in data: #fixme parse license data - e_vars['license']=data['license'].strip() + e_vars['license']=pmsify_license_field(data['license']) e_vars['src_uri']=remote_repository+'/src/contrib/'+data['package']+'_'+data['version']+'.tar.gz' return pms_pkg diff --git a/g_cran/g_cran.py b/g_cran/g_cran.py index 86fb5ea..0eb6515 100644 --- a/g_cran/g_cran.py +++ b/g_cran/g_cran.py @@ -39,9 +39,11 @@ def action_package(repo_location,package_name): #output data for key,value in package.ebuild_vars.iteritems(): if key=='pn' or key=='pv': #readonly vars, we cannot set these in ebuilds - continue - if isinstance(value,str): #if string + pass + elif isinstance(value,str): #if string print key.upper()+'='+value.replace('\n','') + elif isinstance(value,list) and key=='license': + print "|| ( "+' '.join(value)+' )' elif isinstance(value,list): #list, concat items print key.upper()+'='+' '.join(value).replace('\n','') for pms_func in pms_phases: -- cgit v1.2.3-65-gdbad