Remove incomplete MANIFEST support
This incomplete feature contributes to confuse new activity authors and slightly complicates our bundle installation logic. The day someone finds something useful to do with the MANIFEST specification, we can revert this patch in no time. Signed-off-by: Bernie Innocenti <bernie@codewiz.org> Tested-by: Bernie Innocenti <bernie@codewiz.org> Tested-by: James Cameron <quozl@laptop.org> Tested-by: Sascha Silbe <silbe@activitycentral.com> Reviewed-by: Sascha Silbe <silbe@activitycentral.com> [rebased on git master, minor style fix] Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
This commit is contained in:
parent
1f06030269
commit
e7430faac9
@ -142,37 +142,9 @@ class Builder(object):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self):
|
||||||
files = self.config.bundle.get_files()
|
|
||||||
|
|
||||||
if not files:
|
|
||||||
logging.error('No files found, fixing the MANIFEST.')
|
|
||||||
self.fix_manifest()
|
|
||||||
files = self.config.bundle.get_files()
|
|
||||||
|
|
||||||
return files
|
|
||||||
|
|
||||||
def check_manifest(self):
|
|
||||||
missing_files = []
|
|
||||||
|
|
||||||
allfiles = list_files(self.config.source_dir,
|
allfiles = list_files(self.config.source_dir,
|
||||||
IGNORE_DIRS, IGNORE_FILES)
|
IGNORE_DIRS, IGNORE_FILES)
|
||||||
for path in allfiles:
|
return allfiles
|
||||||
if path not in self.config.bundle.manifest:
|
|
||||||
missing_files.append(path)
|
|
||||||
|
|
||||||
return missing_files
|
|
||||||
|
|
||||||
def fix_manifest(self):
|
|
||||||
self.build()
|
|
||||||
|
|
||||||
manifest = self.config.bundle.manifest
|
|
||||||
|
|
||||||
for path in self.check_manifest():
|
|
||||||
manifest.append(path)
|
|
||||||
|
|
||||||
f = open(os.path.join(self.config.source_dir, 'MANIFEST'), 'wb')
|
|
||||||
for line in manifest:
|
|
||||||
f.write(line + '\n')
|
|
||||||
|
|
||||||
|
|
||||||
class Packager(object):
|
class Packager(object):
|
||||||
@ -198,13 +170,6 @@ class XOPackager(Packager):
|
|||||||
bundle_zip = zipfile.ZipFile(self.package_path, 'w',
|
bundle_zip = zipfile.ZipFile(self.package_path, 'w',
|
||||||
zipfile.ZIP_DEFLATED)
|
zipfile.ZIP_DEFLATED)
|
||||||
|
|
||||||
missing_files = self.builder.check_manifest()
|
|
||||||
if missing_files:
|
|
||||||
logging.warn('These files are not included in the manifest ' \
|
|
||||||
'and will not be present in the bundle:\n\n' +
|
|
||||||
'\n'.join(missing_files) +
|
|
||||||
'\n\nUse fix_manifest if you want to add them.')
|
|
||||||
|
|
||||||
for f in self.builder.get_files():
|
for f in self.builder.get_files():
|
||||||
bundle_zip.write(os.path.join(self.config.source_dir, f),
|
bundle_zip.write(os.path.join(self.config.source_dir, f),
|
||||||
os.path.join(self.config.bundle_root_dir, f))
|
os.path.join(self.config.bundle_root_dir, f))
|
||||||
@ -311,14 +276,11 @@ def cmd_dist_xo(config, args):
|
|||||||
|
|
||||||
|
|
||||||
def cmd_fix_manifest(config, args):
|
def cmd_fix_manifest(config, args):
|
||||||
"""Add missing files to the manifest"""
|
'''Add missing files to the manifest (OBSOLETE)'''
|
||||||
|
|
||||||
if args:
|
print 'WARNING: The fix_manifest command is obsolete.'
|
||||||
print 'Usage: %prog fix_manifest'
|
print ' The MANIFEST file is no longer used in bundles,'
|
||||||
return
|
print ' please remove it.'
|
||||||
|
|
||||||
builder = Builder(config)
|
|
||||||
builder.fix_manifest()
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_dist_source(config, args):
|
def cmd_dist_source(config, args):
|
||||||
|
@ -63,7 +63,6 @@ class ActivityBundle(Bundle):
|
|||||||
self._tags = None
|
self._tags = None
|
||||||
self._activity_version = '0'
|
self._activity_version = '0'
|
||||||
self._installation_time = os.stat(path).st_mtime
|
self._installation_time = os.stat(path).st_mtime
|
||||||
self._manifest = None
|
|
||||||
|
|
||||||
info_file = self.get_file('activity/activity.info')
|
info_file = self.get_file('activity/activity.info')
|
||||||
if info_file is None:
|
if info_file is None:
|
||||||
@ -77,74 +76,6 @@ class ActivityBundle(Bundle):
|
|||||||
if self._local_name == None:
|
if self._local_name == None:
|
||||||
self._local_name = self._name
|
self._local_name = self._name
|
||||||
|
|
||||||
def _get_manifest(self):
|
|
||||||
if self._manifest is None:
|
|
||||||
self._manifest = self._read_manifest()
|
|
||||||
return self._manifest
|
|
||||||
|
|
||||||
manifest = property(_get_manifest, None, None,
|
|
||||||
"NOTICE: this property is potentially quite slow, so better make sure "
|
|
||||||
"that it's not called at performance-critical points like shell or "
|
|
||||||
"activity startup.")
|
|
||||||
|
|
||||||
def _raw_manifest(self):
|
|
||||||
f = self.get_file('MANIFEST')
|
|
||||||
if not f:
|
|
||||||
logging.warning('Activity directory lacks a MANIFEST file.')
|
|
||||||
return []
|
|
||||||
|
|
||||||
ret = [line.strip() for line in f.readlines()]
|
|
||||||
f.close()
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def _read_manifest(self):
|
|
||||||
"""return a list with the lines in MANIFEST, with invalid lines
|
|
||||||
replaced by empty lines.
|
|
||||||
|
|
||||||
Since absolute order carries information on file history, it should
|
|
||||||
be preserved. For instance, when renaming a file, you should leave
|
|
||||||
the new name on the same line as the old one.
|
|
||||||
"""
|
|
||||||
logging.debug('STARTUP: Reading manifest')
|
|
||||||
lines = self._raw_manifest()
|
|
||||||
|
|
||||||
# Remove trailing newlines, they do not help keep absolute position.
|
|
||||||
while lines and lines[-1] == '':
|
|
||||||
lines = lines[:-1]
|
|
||||||
|
|
||||||
for num, line in enumerate(lines):
|
|
||||||
if not line:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Remove duplicates
|
|
||||||
if line in lines[0:num]:
|
|
||||||
lines[num] = ''
|
|
||||||
logging.warning('Bundle %s: duplicate entry in MANIFEST: %s',
|
|
||||||
self._name, line)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Remove MANIFEST
|
|
||||||
if line == 'MANIFEST':
|
|
||||||
lines[num] = ''
|
|
||||||
logging.warning('Bundle %s: MANIFEST includes itself: %s',
|
|
||||||
self._name, line)
|
|
||||||
|
|
||||||
# Remove invalid files
|
|
||||||
if not self.is_file(line):
|
|
||||||
lines[num] = ''
|
|
||||||
logging.warning('Bundle %s: invalid entry in MANIFEST: %s',
|
|
||||||
self._name, line)
|
|
||||||
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def get_files(self, manifest=None):
|
|
||||||
files = [line for line in (manifest or self.manifest) if line]
|
|
||||||
|
|
||||||
if self.is_file('MANIFEST'):
|
|
||||||
files.append('MANIFEST')
|
|
||||||
|
|
||||||
return files
|
|
||||||
|
|
||||||
def _parse_info(self, info_file):
|
def _parse_info(self, info_file):
|
||||||
cp = ConfigParser()
|
cp = ConfigParser()
|
||||||
cp.readfp(info_file)
|
cp.readfp(info_file)
|
||||||
@ -309,41 +240,13 @@ class ActivityBundle(Bundle):
|
|||||||
"""Get whether there should be a visible launcher for the activity"""
|
"""Get whether there should be a visible launcher for the activity"""
|
||||||
return self._show_launcher
|
return self._show_launcher
|
||||||
|
|
||||||
def install(self, install_dir=None, strict_manifest=False):
|
def install(self, install_dir=None):
|
||||||
if install_dir is None:
|
if install_dir is None:
|
||||||
install_dir = env.get_user_activities_path()
|
install_dir = env.get_user_activities_path()
|
||||||
|
|
||||||
self._unzip(install_dir)
|
self._unzip(install_dir)
|
||||||
|
|
||||||
install_path = os.path.join(install_dir, self._zip_root_dir)
|
install_path = os.path.join(install_dir, self._zip_root_dir)
|
||||||
|
|
||||||
# List installed files
|
|
||||||
manifestfiles = self.get_files(self._raw_manifest())
|
|
||||||
paths = []
|
|
||||||
for root, dirs_, files in os.walk(install_path):
|
|
||||||
rel_path = root[len(install_path) + 1:]
|
|
||||||
for f in files:
|
|
||||||
paths.append(os.path.join(rel_path, f))
|
|
||||||
|
|
||||||
# Check the list against the MANIFEST
|
|
||||||
for path in paths:
|
|
||||||
if path in manifestfiles:
|
|
||||||
manifestfiles.remove(path)
|
|
||||||
elif path != 'MANIFEST':
|
|
||||||
logging.warning('Bundle %s: %s not in MANIFEST', self._name,
|
|
||||||
path)
|
|
||||||
if strict_manifest:
|
|
||||||
os.remove(os.path.join(install_path, path))
|
|
||||||
|
|
||||||
# Is anything in MANIFEST left over after accounting for all files?
|
|
||||||
if manifestfiles:
|
|
||||||
err = ('Bundle %s: files in MANIFEST not included: %s' %
|
|
||||||
(self._name, str(manifestfiles)))
|
|
||||||
if strict_manifest:
|
|
||||||
raise MalformedBundleException(err)
|
|
||||||
else:
|
|
||||||
logging.warning(err)
|
|
||||||
|
|
||||||
self.install_mime_type(install_path)
|
self.install_mime_type(install_path)
|
||||||
|
|
||||||
return install_path
|
return install_path
|
||||||
|
@ -78,14 +78,6 @@ class Bundle(object):
|
|||||||
'%s' % (self._path, exception))
|
'%s' % (self._path, exception))
|
||||||
self._check_zip_bundle()
|
self._check_zip_bundle()
|
||||||
|
|
||||||
# manifest = self._get_file(self._infodir + '/contents')
|
|
||||||
# if manifest is None:
|
|
||||||
# raise MalformedBundleException('No manifest file')
|
|
||||||
|
|
||||||
# signature = self._get_file(self._infodir + '/contents.sig')
|
|
||||||
# if signature is None:
|
|
||||||
# raise MalformedBundleException('No signature file')
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._zip_file is not None:
|
if self._zip_file is not None:
|
||||||
self._zip_file.close()
|
self._zip_file.close()
|
||||||
@ -174,7 +166,6 @@ class Bundle(object):
|
|||||||
# correctly by hand, but handling all the oddities of
|
# correctly by hand, but handling all the oddities of
|
||||||
# Windows/UNIX mappings, extension attributes, deprecated
|
# Windows/UNIX mappings, extension attributes, deprecated
|
||||||
# features, etc makes it impractical.
|
# features, etc makes it impractical.
|
||||||
# FIXME: use manifest
|
|
||||||
if os.spawnlp(os.P_WAIT, 'unzip', 'unzip', '-o', self._path,
|
if os.spawnlp(os.P_WAIT, 'unzip', 'unzip', '-o', self._path,
|
||||||
'-x', 'mimetype', '-d', install_dir):
|
'-x', 'mimetype', '-d', install_dir):
|
||||||
# clean up install dir after failure
|
# clean up install dir after failure
|
||||||
|
Loading…
Reference in New Issue
Block a user