Replace remaining file() usage

This commit is contained in:
Daniel Martí 2016-01-04 17:59:47 +01:00
parent 5026d4e08b
commit fc21dbc667
2 changed files with 42 additions and 38 deletions

View file

@ -1013,15 +1013,16 @@ def get_library_references(root_dir):
proppath = os.path.join(root_dir, 'project.properties') proppath = os.path.join(root_dir, 'project.properties')
if not os.path.isfile(proppath): if not os.path.isfile(proppath):
return libraries return libraries
for line in file(proppath): with open(proppath, 'r') as f:
if not line.startswith('android.library.reference.'): for line in f:
continue if not line.startswith('android.library.reference.'):
path = line.split('=')[1].strip() continue
relpath = os.path.join(root_dir, path) path = line.split('=')[1].strip()
if not os.path.isdir(relpath): relpath = os.path.join(root_dir, path)
continue if not os.path.isdir(relpath):
logging.debug("Found subproject at %s" % path) continue
libraries.append(path) logging.debug("Found subproject at %s" % path)
libraries.append(path)
return libraries return libraries
@ -1087,25 +1088,26 @@ def parse_androidmanifests(paths, app):
package = None package = None
if gradle: if gradle:
for line in file(path): with open(path, 'r') as f:
if gradle_comment.match(line): for line in f:
continue if gradle_comment.match(line):
# Grab first occurence of each to avoid running into continue
# alternative flavours and builds. # Grab first occurence of each to avoid running into
if not package: # alternative flavours and builds.
matches = psearch_g(line) if not package:
if matches: matches = psearch_g(line)
s = matches.group(2) if matches:
if app_matches_packagename(app, s): s = matches.group(2)
package = s if app_matches_packagename(app, s):
if not version: package = s
matches = vnsearch_g(line) if not version:
if matches: matches = vnsearch_g(line)
version = matches.group(2) if matches:
if not vercode: version = matches.group(2)
matches = vcsearch_g(line) if not vercode:
if matches: matches = vcsearch_g(line)
vercode = matches.group(1) if matches:
vercode = matches.group(1)
else: else:
try: try:
xml = parse_xml(path) xml = parse_xml(path)
@ -1531,12 +1533,13 @@ class KnownApks:
self.path = os.path.join('stats', 'known_apks.txt') self.path = os.path.join('stats', 'known_apks.txt')
self.apks = {} self.apks = {}
if os.path.isfile(self.path): if os.path.isfile(self.path):
for line in file(self.path): with open(self.path, 'r') as f:
t = line.rstrip().split(' ') for line in f:
if len(t) == 2: t = line.rstrip().split(' ')
self.apks[t[0]] = (t[1], None) if len(t) == 2:
else: self.apks[t[0]] = (t[1], None)
self.apks[t[0]] = (t[1], time.strptime(t[2], '%Y-%m-%d')) else:
self.apks[t[0]] = (t[1], time.strptime(t[2], '%Y-%m-%d'))
self.changed = False self.changed = False
def writeifchanged(self): def writeifchanged(self):

View file

@ -199,10 +199,11 @@ def scan_source(build_dir, root_dir, build):
elif ext == 'java': elif ext == 'java':
if not os.path.isfile(fp): if not os.path.isfile(fp):
continue continue
for line in file(fp): with open(fp, 'r') as f:
if 'DexClassLoader' in line: for line in f:
count += handleproblem('DexClassLoader', fd, fp) if 'DexClassLoader' in line:
break count += handleproblem('DexClassLoader', fd, fp)
break
elif ext == 'gradle': elif ext == 'gradle':
if not os.path.isfile(fp): if not os.path.isfile(fp):