Skip to content

Commit

Permalink
Progress for implementing the --extract_license option
Browse files Browse the repository at this point in the history
  • Loading branch information
chinyeungli committed May 5, 2016
1 parent 0437037 commit 9f85bf2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
12 changes: 11 additions & 1 deletion about_code_tool/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def generate(mapping, extract_license, location, base_dir, policy=None, conf_loc
about.about_resource.value[basename(about.about_file_path)] = None
about.about_resource.original_value = basename(about.about_file_path)
about.about_resource.present = True

# Write the ABOUT file and check does the referenced file exist
not_exist_errors = about.dump(dump_loc,
with_empty=with_empty,
Expand All @@ -252,7 +253,16 @@ def generate(mapping, extract_license, location, base_dir, policy=None, conf_loc
errors.append(Error(ERROR, e))
if gen_license:
# Write generated LICENSE file
about.dump_lic(dump_loc, dje_license_dict)
lic_name, lic_context, lic_url = about.dump_lic(dump_loc, dje_license_dict)
if not about.license_name.present:
about.license_name.value = lic_name
about.license_name.present = True
if not about.license_file.present:
about.license_file.value = about.dje_license_key.value + u'.LICENSE'
about.license_file.present = True
if not about.license_url.present:
about.license_url.value = lic_url
about.license_url.present = True
except Exception, e:
# only keep the first 100 char of the exception
emsg = repr(e)[:100]
Expand Down
31 changes: 10 additions & 21 deletions about_code_tool/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,32 +989,21 @@ def dump_lic(self, location, license_dict):
"""
Write LICENSE files
"""
errors = []
license_name = license_context = license_url = ''
loc = util.to_posix(location)
parent = posixpath.dirname(loc)
if not os.path.exists(parent):
os.makedirs(parent)
about_file_path = loc

if self.dje_license_key:
#print(self.about_file_path)
#print(self.dje_license_key.value)
#print(license_dict)
print(license_dict[self.dje_license_key.value])
"""if not about_file_path.endswith('.ABOUT'):
if about_file_path.endswith('/'):
about_file_path = util.to_posix(os.path.join(parent, os.path.basename(parent)))
about_file_path += '.ABOUT'
with codecs.open(about_file_path, mode='wb', encoding='utf-8') as dumped:
dumped.write(self.dumps(with_absent, with_empty, with_capture))
for about_resource_value in self.about_resource.value:
path = posixpath.join(dirname(about_file_path), about_resource_value)
if not posixpath.exists(path):
msg = (u'The reference file : '
u'%(path)s '
u'does not exist' % locals())
errors.append(msg)
return errors"""
if self.dje_license_key.present:
lic_key = self.dje_license_key.value
if license_dict[lic_key]:
license_path = posixpath.join(parent, lic_key)
license_path += u'.LICENSE'
license_name, license_context, license_url = license_dict[lic_key]
with codecs.open(license_path, mode='wb', encoding='utf-8') as lic:
lic.write(license_context)
return license_name, license_context, license_url

# valid field name
field_name = r'(?P<name>[a-z][0-9a-z_]*)'
Expand Down

0 comments on commit 9f85bf2

Please sign in to comment.