From cb10f0df09b53c10e2b571a69004bf62c105638d Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 14 Sep 2017 08:44:43 +0200 Subject: [PATCH] standardize os.walk() var names based on Python 3.5 docs There were multiple conventions used in the code, but mostly it was already using the convention from the docs, so this converts things to using that convention: https://docs.python.org/3/library/os.html#os.walk --- fdroidserver/btlog.py | 10 +++++----- fdroidserver/build.py | 18 +++++++++--------- fdroidserver/checkupdates.py | 6 +++--- fdroidserver/common.py | 6 +++--- fdroidserver/lint.py | 12 ++++++------ fdroidserver/scanner.py | 10 +++++----- fdroidserver/server.py | 8 ++++---- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/fdroidserver/btlog.py b/fdroidserver/btlog.py index 452addca..8d31596b 100755 --- a/fdroidserver/btlog.py +++ b/fdroidserver/btlog.py @@ -117,12 +117,12 @@ For more info on this idea: jarin.close() gitrepo.index.add([repof, ]) - files = [] - for root, dirs, filenames in os.walk(repodir): - for f in filenames: - files.append(os.path.relpath(os.path.join(root, f), repodir)) + output_files = [] + for root, dirs, files in os.walk(repodir): + for f in files: + output_files.append(os.path.relpath(os.path.join(root, f), repodir)) output = collections.OrderedDict() - for f in sorted(files): + for f in sorted(output_files): repofile = os.path.join(repodir, f) stat = os.stat(repofile) output[f] = ( diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 5dfe63ba..88a1d0d3 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -96,19 +96,19 @@ def build_server(app, build, vcs, build_dir, output_dir, log_dir, force): # Helper to copy the contents of a directory to the server... def send_dir(path): - root = os.path.dirname(path) + startroot = os.path.dirname(path) main = os.path.basename(path) ftp.mkdir(main) - for r, d, f in os.walk(path): - rr = os.path.relpath(r, root) + for root, dirs, files in os.walk(path): + rr = os.path.relpath(root, startroot) ftp.chdir(rr) - for dd in d: - ftp.mkdir(dd) - for ff in f: - lfile = os.path.join(root, rr, ff) + for d in dirs: + ftp.mkdir(d) + for f in files: + lfile = os.path.join(startroot, rr, f) if not os.path.islink(lfile): - ftp.put(lfile, ff) - ftp.chmod(ff, os.stat(lfile).st_mode) + ftp.put(lfile, f) + ftp.chmod(f, os.stat(lfile).st_mode) for i in range(len(rr.split('/'))): ftp.chdir('..') ftp.chdir('..') diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index 217139d1..c118c008 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -302,10 +302,10 @@ def check_gplay(app): # Return all directories under startdir that contain any of the manifest # files, and thus are probably an Android project. def dirs_with_manifest(startdir): - for r, d, f in os.walk(startdir): - if any(m in f for m in [ + for root, dirs, files in os.walk(startdir): + if any(m in files for m in [ 'AndroidManifest.xml', 'pom.xml', 'build.gradle']): - yield r + yield root # Tries to find a new subdir starting from the root build_dir. Returns said diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 182949d9..79d58af7 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -1022,9 +1022,9 @@ def retrieve_string(app_dir, string, xmlfiles=None): os.path.join(app_dir, 'res'), os.path.join(app_dir, 'src', 'main', 'res'), ]: - for r, d, f in os.walk(res_dir): - if os.path.basename(r) == 'values': - xmlfiles += [os.path.join(r, x) for x in f if x.endswith('.xml')] + for root, dirs, files in os.walk(res_dir): + if os.path.basename(root) == 'values': + xmlfiles += [os.path.join(root, x) for x in files if x.endswith('.xml')] name = string[len('@string/'):] diff --git a/fdroidserver/lint.py b/fdroidserver/lint.py index 04ef0f9c..451f4f29 100644 --- a/fdroidserver/lint.py +++ b/fdroidserver/lint.py @@ -358,21 +358,21 @@ def check_license_tag(app): def check_extlib_dir(apps): dir_path = os.path.join('build', 'extlib') - files = set() - for root, dirs, names in os.walk(dir_path): - for name in names: - files.add(os.path.join(root, name)[len(dir_path) + 1:]) + unused_extlib_files = set() + for root, dirs, files in os.walk(dir_path): + for name in files: + unused_extlib_files.add(os.path.join(root, name)[len(dir_path) + 1:]) used = set() for app in apps: for build in app.builds: for path in build.extlibs: - if path not in files: + if path not in unused_extlib_files: yield "%s: Unknown extlib %s in build '%s'" % (app.id, path, build.versionName) else: used.add(path) - for path in files.difference(used): + for path in unused_extlib_files.difference(used): if any(path.endswith(s) for s in [ '.gitignore', 'source.txt', 'origin.txt', 'md5.txt', diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index f768e678..63361e86 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -165,20 +165,20 @@ def scan_source(build_dir, build): return any(command.match(line) for command in gradle_compile_commands) # Iterate through all files in the source code - for dirpath, dirnames, filenames in os.walk(build_dir, topdown=True): + for root, dirs, files in os.walk(build_dir, topdown=True): # It's topdown, so checking the basename is enough for ignoredir in ('.hg', '.git', '.svn', '.bzr'): - if ignoredir in dirnames: - dirnames.remove(ignoredir) + if ignoredir in dirs: + dirs.remove(ignoredir) - for curfile in filenames: + for curfile in files: if curfile in ['.DS_Store']: continue # Path (relative) to the file - filepath = os.path.join(dirpath, curfile) + filepath = os.path.join(root, curfile) if os.path.islink(filepath): continue diff --git a/fdroidserver/server.py b/fdroidserver/server.py index 3b36ecee..6ae22bfd 100644 --- a/fdroidserver/server.py +++ b/fdroidserver/server.py @@ -154,7 +154,7 @@ def update_awsbucket_libcloud(repo_section): if obj.name.startswith(upload_dir + '/'): objs[obj.name] = obj - for root, _, files in os.walk(os.path.join(os.getcwd(), repo_section)): + for root, dirs, files in os.walk(os.path.join(os.getcwd(), repo_section)): for name in files: upload = False file_to_upload = os.path.join(root, name) @@ -307,9 +307,9 @@ def update_localcopy(repo_section, local_copy_dir): def _get_size(start_path='.'): '''get size of all files in a dir https://stackoverflow.com/a/1392549''' total_size = 0 - for dirpath, dirnames, filenames in os.walk(start_path): - for f in filenames: - fp = os.path.join(dirpath, f) + for root, dirs, files in os.walk(start_path): + for f in files: + fp = os.path.join(root, f) total_size += os.path.getsize(fp) return total_size -- 2.30.2