зеркало из https://github.com/mozilla/gecko-dev.git
Bug 835309 - Fix JarFileReader.readlines() and make flake8 happier. r=gps
This commit is contained in:
Родитель
7c163ea485
Коммит
aec48ba2bc
|
@ -151,7 +151,7 @@ class VersionFlag(object):
|
|||
elif len(value) > 1 and value[0] in ['<', '>']:
|
||||
if value[1] == '=':
|
||||
if len(value) < 3:
|
||||
return errors.fatal('Malformed flag: %s' % definition)
|
||||
return errors.fatal('Malformed flag: %s' % definition)
|
||||
self.values.append((value[0:2], LooseVersion(value[2:])))
|
||||
else:
|
||||
self.values.append((value[0], LooseVersion(value[1:])))
|
||||
|
|
|
@ -324,6 +324,7 @@ MANIFESTS_TYPES = dict([(c.type, c) for c in globals().values()
|
|||
|
||||
MANIFEST_RE = re.compile(r'\s*#.*$')
|
||||
|
||||
|
||||
def parse_manifest_line(base, line):
|
||||
'''
|
||||
Parse a line from a manifest file with the given base directory and
|
||||
|
|
|
@ -288,7 +288,7 @@ class ManifestFile(BaseFile):
|
|||
the manifest.
|
||||
'''
|
||||
return BytesIO(''.join('%s\n' % e.rebase(self._base)
|
||||
for e in self._entries))
|
||||
for e in self._entries))
|
||||
|
||||
def __iter__(self):
|
||||
'''
|
||||
|
@ -318,7 +318,7 @@ class MinifiedProperties(BaseFile):
|
|||
the properties file.
|
||||
'''
|
||||
return BytesIO(''.join(l for l in self._file.open().readlines()
|
||||
if not l.startswith('#')))
|
||||
if not l.startswith('#')))
|
||||
|
||||
|
||||
class FileFinder(object):
|
||||
|
|
|
@ -65,7 +65,7 @@ class JarStruct(object):
|
|||
'''
|
||||
assert self.MAGIC and isinstance(self.STRUCT, OrderedDict)
|
||||
self.size_fields = set(t for t in self.STRUCT.itervalues()
|
||||
if not t in JarStruct.TYPE_MAPPING)
|
||||
if not t in JarStruct.TYPE_MAPPING)
|
||||
self._values = {}
|
||||
if data:
|
||||
self._init_data(data)
|
||||
|
@ -277,7 +277,7 @@ class JarFileReader(object):
|
|||
Return a list containing all the lines of data in the uncompressed
|
||||
data.
|
||||
'''
|
||||
return self.read().splitlines()
|
||||
return self.read().splitlines(True)
|
||||
|
||||
def seek(self, pos, whence=os.SEEK_SET):
|
||||
'''
|
||||
|
@ -375,7 +375,7 @@ class JarReader(object):
|
|||
xattr = entry['external_attr']
|
||||
# Skip directories
|
||||
if (host == 0 and xattr & 0x10) or (host == 3 and
|
||||
xattr & (040000 << 16)):
|
||||
xattr & (040000 << 16)):
|
||||
continue
|
||||
entries[entry['filename']] = entry
|
||||
if entry['offset'] < preload:
|
||||
|
@ -416,7 +416,8 @@ class JarReader(object):
|
|||
if key in header and header[key] != value:
|
||||
raise JarReaderError('Central directory and file header ' +
|
||||
'mismatch. Corrupted archive?')
|
||||
return JarFileReader(header, self._data[entry['offset'] + header.size:])
|
||||
return JarFileReader(header,
|
||||
self._data[entry['offset'] + header.size:])
|
||||
|
||||
def __iter__(self):
|
||||
'''
|
||||
|
@ -529,7 +530,7 @@ class JarWriter(object):
|
|||
end['disk_entries'] = len(self._contents)
|
||||
end['cdir_entries'] = end['disk_entries']
|
||||
end['cdir_size'] = reduce(lambda x, y: x + y[0].size,
|
||||
self._contents.values(), 0)
|
||||
self._contents.values(), 0)
|
||||
# On optimized archives, store the preloaded size and the central
|
||||
# directory entries, followed by the first end of central directory.
|
||||
if self._optimize:
|
||||
|
@ -584,7 +585,8 @@ class JarWriter(object):
|
|||
data.seek(0)
|
||||
deflater.write(data.read())
|
||||
else:
|
||||
raise JarWriterError("Don't know how to handle %s" % type(data))
|
||||
raise JarWriterError("Don't know how to handle %s" %
|
||||
type(data))
|
||||
# Fill a central directory entry for this new member.
|
||||
entry = JarCdirEntry()
|
||||
# Not storing as created on unix, which avoids having to deal with
|
||||
|
|
|
@ -19,7 +19,6 @@ from mozpack.copier import (
|
|||
FileRegistry,
|
||||
Jarrer,
|
||||
)
|
||||
from mozpack.errors import errors
|
||||
|
||||
STARTUP_CACHE_PATHS = [
|
||||
'jsloader',
|
||||
|
@ -61,6 +60,7 @@ Formatters all take a FileCopier instance they will fill with the packaged
|
|||
data.
|
||||
'''
|
||||
|
||||
|
||||
class FlatFormatter(object):
|
||||
'''
|
||||
Formatter for the flat package format.
|
||||
|
@ -192,8 +192,8 @@ class JarFormatter(FlatFormatter):
|
|||
return self.copier.contains(path)
|
||||
if not self.copier.contains(chrome + '.jar'):
|
||||
return False
|
||||
return self.copier[chrome + '.jar'].contains(mozpack.path.relpath(path,
|
||||
chrome))
|
||||
return self.copier[chrome + '.jar']. \
|
||||
contains(mozpack.path.relpath(path, chrome))
|
||||
|
||||
|
||||
class OmniJarFormatter(FlatFormatter):
|
||||
|
|
|
@ -25,7 +25,6 @@ from mozpack.packager.formats import (
|
|||
STARTUP_CACHE_PATHS,
|
||||
)
|
||||
from urlparse import urlparse
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
class UnpackFinder(FileFinder):
|
||||
|
|
|
@ -233,7 +233,6 @@ class TestOmniJarFormatter(TestWithTmpDir):
|
|||
'app/components/foo.so', 'app/foo'
|
||||
])
|
||||
|
||||
|
||||
def test_omnijar_is_resource(self):
|
||||
registry = FileRegistry()
|
||||
f = OmniJarFormatter(registry, 'omni.foo', non_resources=[
|
||||
|
@ -250,12 +249,13 @@ class TestOmniJarFormatter(TestWithTmpDir):
|
|||
self.assertTrue(f.is_resource(base + 'components/foo.js'))
|
||||
self.assertFalse(f.is_resource(base + 'components/foo.so'))
|
||||
self.assertTrue(f.is_resource(base + 'res/foo.css'))
|
||||
self.assertFalse( f.is_resource(base + 'res/cursors/foo.png'))
|
||||
self.assertFalse(f.is_resource(base + 'res/cursors/foo.png'))
|
||||
self.assertFalse(f.is_resource(base + 'res/MainMenu.nib/'))
|
||||
self.assertTrue(f.is_resource(base + 'defaults/pref/foo.js'))
|
||||
self.assertFalse(
|
||||
f.is_resource(base + 'defaults/pref/channel-prefs.js'))
|
||||
self.assertTrue(f.is_resource(base + 'defaults/preferences/foo.js'))
|
||||
self.assertTrue(
|
||||
f.is_resource(base + 'defaults/preferences/foo.js'))
|
||||
self.assertFalse(
|
||||
f.is_resource(base + 'defaults/preferences/channel-prefs.js'))
|
||||
self.assertTrue(f.is_resource(base + 'modules/foo.jsm'))
|
||||
|
|
|
@ -123,7 +123,6 @@ class UnifiedFinder(FileFinder):
|
|||
if not isinstance(file1, ExecutableFile) and \
|
||||
not isinstance(file2, ExecutableFile):
|
||||
from difflib import unified_diff
|
||||
import sys
|
||||
for line in unified_diff(file1.open().readlines(),
|
||||
file2.open().readlines(),
|
||||
os.path.join(self._base1.base, path),
|
||||
|
|
|
@ -5,10 +5,7 @@
|
|||
import sys
|
||||
import hashlib
|
||||
from mozpack.packager.unpack import UnpackFinder
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from simplejson import OrderedDict
|
||||
from collections import OrderedDict
|
||||
|
||||
'''
|
||||
Find files duplicated in a given packaged directory, independently of its
|
||||
|
|
|
@ -7,7 +7,6 @@ Replace localized parts of a packaged directory with data from a langpack
|
|||
directory.
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
import mozpack.path
|
||||
from mozpack.packager.formats import (
|
||||
|
|
|
@ -28,8 +28,6 @@ import buildconfig
|
|||
from argparse import ArgumentParser
|
||||
from createprecomplete import generate_precomplete
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from StringIO import StringIO
|
||||
import subprocess
|
||||
import platform
|
||||
|
@ -328,7 +326,8 @@ def main():
|
|||
libname = '%s%s' % (libbase, buildconfig.substs['DLL_SUFFIX'])
|
||||
if copier.contains(libname):
|
||||
copier.add(libbase + '.chk',
|
||||
LibSignFile(os.path.join(args.destination, libname)))
|
||||
LibSignFile(os.path.join(args.destination,
|
||||
libname)))
|
||||
|
||||
# Setup preloading
|
||||
if args.jarlogs:
|
||||
|
|
|
@ -7,6 +7,7 @@ import os
|
|||
from mozpack.packager.unpack import unpack
|
||||
import buildconfig
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print >>sys.stderr, "Usage: %s directory" % \
|
||||
|
|
Загрузка…
Ссылка в новой задаче