From fc21dbc6672b977bcdd3bc110f05577b3addceaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 4 Jan 2016 17:59:47 +0100 Subject: [PATCH] Replace remaining file() usage --- fdroidserver/common.py | 71 +++++++++++++++++++++-------------------- fdroidserver/scanner.py | 9 +++--- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index ed8fa1f9..8c71a230 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1013,15 +1013,16 @@ def get_library_references(root_dir): proppath = os.path.join(root_dir, 'project.properties') if not os.path.isfile(proppath): return libraries - for line in file(proppath): - if not line.startswith('android.library.reference.'): - continue - path = line.split('=')[1].strip() - relpath = os.path.join(root_dir, path) - if not os.path.isdir(relpath): - continue - logging.debug("Found subproject at %s" % path) - libraries.append(path) + with open(proppath, 'r') as f: + for line in f: + if not line.startswith('android.library.reference.'): + continue + path = line.split('=')[1].strip() + relpath = os.path.join(root_dir, path) + if not os.path.isdir(relpath): + continue + logging.debug("Found subproject at %s" % path) + libraries.append(path) return libraries @@ -1087,25 +1088,26 @@ def parse_androidmanifests(paths, app): package = None if gradle: - for line in file(path): - if gradle_comment.match(line): - continue - # Grab first occurence of each to avoid running into - # alternative flavours and builds. - if not package: - matches = psearch_g(line) - if matches: - s = matches.group(2) - if app_matches_packagename(app, s): - package = s - if not version: - matches = vnsearch_g(line) - if matches: - version = matches.group(2) - if not vercode: - matches = vcsearch_g(line) - if matches: - vercode = matches.group(1) + with open(path, 'r') as f: + for line in f: + if gradle_comment.match(line): + continue + # Grab first occurence of each to avoid running into + # alternative flavours and builds. + if not package: + matches = psearch_g(line) + if matches: + s = matches.group(2) + if app_matches_packagename(app, s): + package = s + if not version: + matches = vnsearch_g(line) + if matches: + version = matches.group(2) + if not vercode: + matches = vcsearch_g(line) + if matches: + vercode = matches.group(1) else: try: xml = parse_xml(path) @@ -1531,12 +1533,13 @@ class KnownApks: self.path = os.path.join('stats', 'known_apks.txt') self.apks = {} if os.path.isfile(self.path): - for line in file(self.path): - t = line.rstrip().split(' ') - if len(t) == 2: - self.apks[t[0]] = (t[1], None) - else: - self.apks[t[0]] = (t[1], time.strptime(t[2], '%Y-%m-%d')) + with open(self.path, 'r') as f: + for line in f: + t = line.rstrip().split(' ') + if len(t) == 2: + self.apks[t[0]] = (t[1], None) + else: + self.apks[t[0]] = (t[1], time.strptime(t[2], '%Y-%m-%d')) self.changed = False def writeifchanged(self): diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index d8f568c4..53c938fb 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -199,10 +199,11 @@ def scan_source(build_dir, root_dir, build): elif ext == 'java': if not os.path.isfile(fp): continue - for line in file(fp): - if 'DexClassLoader' in line: - count += handleproblem('DexClassLoader', fd, fp) - break + with open(fp, 'r') as f: + for line in f: + if 'DexClassLoader' in line: + count += handleproblem('DexClassLoader', fd, fp) + break elif ext == 'gradle': if not os.path.isfile(fp):