chiark / gitweb /
standardize os.walk() var names based on Python 3.5 docs
authorHans-Christoph Steiner <hans@eds.org>
Thu, 14 Sep 2017 06:44:43 +0000 (08:44 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Fri, 15 Sep 2017 09:37:21 +0000 (11:37 +0200)
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
fdroidserver/build.py
fdroidserver/checkupdates.py
fdroidserver/common.py
fdroidserver/lint.py
fdroidserver/scanner.py
fdroidserver/server.py

index 452addca1dcc9d84d45e4bfae2356a7e9623a1f5..8d31596bbe7b04c77740bea65f7cac92c213989f 100755 (executable)
@@ -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] = (
index 5dfe63ba747085f2bba260e4b3daa732ed528920..88a1d0d3a46947174c9558d4a3005bf350b0af45 100644 (file)
@@ -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(rroot)
+            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('..')
index 217139d19a956fb052d5ac5f5365e89615ba5f49..c118c0083798ca070bb6ed398be8632c74eb8d19 100644 (file)
@@ -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
index 182949d928ecc8162d29b6e0b385f0b7f451ab97..79d58af75c48a5610dff9d4b2196133d1576b76d 100644 (file)
@@ -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/'):]
 
index 04ef0f9cbbdb202cddfe2bcfaff1472b48256e75..451f4f29aa4509027231fc50f11faa824b0ca456 100644 (file)
@@ -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',
index f768e6788a98d6f9a1cdc5d89f512df88d3a3ef4..63361e860a6b1d93c8847df32bc28c78a49d2ffa 100644 (file)
@@ -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
index 3b36eceeac96a8fc110bfa3f99ec932b9ebc1c0e..6ae22bfd1a5706a2039cc3998a7790130b9ae5f3 100644 (file)
@@ -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