chiark / gitweb /
Apply some autopep8-python2 suggestions
[fdroidserver.git] / fdroidserver / lint.py
index a5ff34d20b84816c5c338d54e4a5f57220c662e5..8cf1bf61d903d340f44c8f121f7ae1f8dbbd71d5 100644 (file)
@@ -33,7 +33,7 @@ regex_warnings = {
          "github URLs should always use https:// not http://"),
         (re.compile(r'.*[^sS]://code\.google\.com/.*'),
          "code.google.com URLs should always use https:// not http://"),
-        ],
+    ],
     'Source Code': [
         (re.compile(r'.*[^sS]://github\.com/.*'),
          "github URLs should always use https:// (not http://, git://, or git@)"),
@@ -45,7 +45,7 @@ regex_warnings = {
          "dl.google.com URLs should always use https:// not http://"),
         (re.compile(r'.*[^sS]://gitorious\.org/.*'),
          "gitorious URLs should always use https:// (not http://, git://, or git@)"),
-        ],
+    ],
     'Repo': [
         (re.compile(r'.*[^sS]://code\.google\.com/.*'),
          "code.google.com URLs should always use https:// not http://"),
@@ -61,7 +61,7 @@ regex_warnings = {
          "Apache SVN URLs should always use https:// (not http:// or svn://)"),
         (re.compile(r'.*[^sS]://svn\.code\.sf\.net/.*'),
          "Sourceforge SVN URLs should always use https:// (not http:// or svn://)"),
-        ],
+    ],
     'Issue Tracker': [
         (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
          "/issues is missing"),
@@ -73,23 +73,25 @@ regex_warnings = {
          "github URLs should always use https:// not http://"),
         (re.compile(r'.*[^sS]://gitorious\.org/.*'),
          "gitorious URLs should always use https:// not http://"),
-        ],
+    ],
     'License': [
         (re.compile(r'^(|None|Unknown)$'),
          "No license specified"),
-        ],
+    ],
     'Summary': [
         (re.compile(r'^$'),
          "Summary yet to be filled"),
-        ],
+    ],
     'Description': [
         (re.compile(r'^No description available$'),
          "Description yet to be filled"),
-        (re.compile(r'[ ]*[*#][^ .]'),
+        (re.compile(r'\s*[*#][^ .]'),
          "Invalid bulleted list"),
-        (re.compile(r'^ '),
+        (re.compile(r'^\s'),
          "Unnecessary leading space"),
-        ],
+        (re.compile(r'.*\s$'),
+         "Unnecessary trailing space"),
+    ],
 }
 
 regex_pedantic = {
@@ -98,52 +100,46 @@ regex_pedantic = {
          "Appending .git is not necessary"),
         (re.compile(r'.*code\.google\.com/p/[^/]+/[^w]'),
          "Possible incorrect path appended to google code project site"),
-        ],
+    ],
     'Source Code': [
         (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
          "Appending .git is not necessary"),
         (re.compile(r'.*code\.google\.com/p/[^/]+/source/.*'),
          "/source is often enough on its own"),
-        ],
+    ],
     'Repo': [
         (re.compile(r'^http://.*'),
          "use https:// if available"),
         (re.compile(r'^svn://.*'),
          "use https:// if available"),
-        ],
+    ],
     'Issue Tracker': [
         (re.compile(r'.*code\.google\.com/p/[^/]+/issues/.*'),
          "/issues is often enough on its own"),
         (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
          "/issues is often enough on its own"),
-        ],
+    ],
     'Summary': [
-        (re.compile(r'^[a-z]'),
-         "No capitalization was done"),
-        (re.compile(r'.*\bandroid\b.*', re.IGNORECASE),
-         "No need to specify that the app is for Android"),
-        (re.compile(r'.*\b(app|application)\b.*', re.IGNORECASE),
-         "No need to specify that the app is... an app"),
         (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
          "No need to specify that the app is Free Software"),
         (re.compile(r'.*[a-z0-9][.,!?][ $]'),
          "Punctuation should be avoided"),
-        ],
-    }
+    ],
+}
 
 
 def main():
 
-    global config, options, appid, count
-    appid = None
+    global config, options, curid, count
+    curid = None
 
     count = Counter()
 
     def warn(message):
-        global appid, count
-        if appid:
-            print "%s:" % appid
-            appid = None
+        global curid, count
+        if curid:
+            print "%s:" % curid
+            curid = None
             count['app'] += 1
         print '    %s' % message
         count['warn'] += 1
@@ -169,20 +165,29 @@ def main():
     apps = common.read_app_args(args, allapps, False)
 
     for appid, app in apps.iteritems():
-        lastcommit = ''
-
         if app['Disabled']:
             continue
 
+        curid = appid
+        count['app_total'] += 1
+
+        curbuild = None
         for build in app['builds']:
-            if build['commit'] and not build['disable']:
-                lastcommit = build['commit']
+            if not curbuild or int(build['vercode']) > int(curbuild['vercode']):
+                curbuild = build
 
         # Potentially incorrect UCM
-        if (app['Update Check Mode'] == 'RepoManifest' and
-                any(s in lastcommit for s in '.,_-/')):
+        if (curbuild and curbuild['commit']
+                and app['Update Check Mode'] == 'RepoManifest' and
+                any(s in curbuild['commit'] for s in '.,_-/')):
             pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
-                lastcommit, app['Update Check Mode']))
+                curbuild['commit'], app['Update Check Mode']))
+
+        # Dangerous auto updates
+        if curbuild and app['Auto Update Mode'] != 'None':
+            for flag in ['target', 'srclibs', 'scanignore']:
+                if curbuild[flag]:
+                    pwarn("Auto Update Mode is enabled but '%s' is manually set at '%s'" % (flag, curbuild[flag]))
 
         # Summary size limit
         summ_chars = len(app['Summary'])
@@ -190,17 +195,20 @@ def main():
             warn("Summary of length %s is over the %i char limit" % (
                 summ_chars, config['char_limits']['Summary']))
 
-        # Redundant summaries
-        summary = app['Summary']
+        # Redundant info
+        if app['Web Site'] and app['Source Code']:
+            if app['Web Site'].lower() == app['Source Code'].lower():
+                warn("Website '%s' is just the app's source code link" % app['Web Site'])
+                app['Web Site'] = ''
+
         name = app['Name'] or app['Auto Name']
-        if summary and name:
-            summary_l = summary.lower()
-            name_l = name.lower()
-            if summary_l == name_l:
-                warn("Summary '%s' is just the app's name" % summary)
-            elif (summary_l in name_l or name_l in summary_l):
-                pwarn("Summary '%s' probably contains redundant info already in app name '%s'" % (
-                    summary, name))
+        if app['Summary'] and name:
+            if app['Summary'].lower() == name.lower():
+                warn("Summary '%s' is just the app's name" % app['Summary'])
+
+        if app['Summary'] and app['Description'] and len(app['Description']) == 1:
+            if app['Summary'].lower() == app['Description'][0].lower():
+                warn("Description '%s' is just the app's summary" % app['Summary'])
 
         # Description size limit
         desc_chars = sum(len(l) for l in app['Description'])
@@ -248,10 +256,11 @@ def main():
                         # TODO: This should not be pedantic!
                         pwarn("'%s' used in %s '%s'" % (s, flag, build[flag]))
 
-        if not appid:
+        if not curid:
             print
 
-    logging.info("Found a total of %i warnings in %i apps." % (count['warn'], count['app']))
+    logging.info("Found a total of %i warnings in %i apps out of %i total." % (
+        count['warn'], count['app'], count['app_total']))
 
 if __name__ == "__main__":
     main()