diff options
author | Auke Booij (tulcod) <auke@tulcod.com> | 2010-06-26 21:42:50 +0200 |
---|---|---|
committer | Auke Booij (tulcod) <auke@tulcod.com> | 2010-06-26 22:03:51 +0200 |
commit | 7ec3dd558d1cf598b924eda885e05d21c75abefa (patch) | |
tree | da9195f993974257e32633ac478429f3149c3854 /g_cran | |
parent | Forgot a return statement (diff) | |
download | g-cran-7ec3dd558d1cf598b924eda885e05d21c75abefa.tar.gz g-cran-7ec3dd558d1cf598b924eda885e05d21c75abefa.tar.bz2 g-cran-7ec3dd558d1cf598b924eda885e05d21c75abefa.zip |
Fix license parsing
Diffstat (limited to 'g_cran')
-rw-r--r-- | g_cran/cran_read.py | 49 | ||||
-rw-r--r-- | g_cran/g_cran.py | 6 |
2 files changed, 52 insertions, 3 deletions
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: |