Răsfoiți Sursa

Revert "HUE-8737 [core] Futurize tools/app_reg for Python 3.5"

This reverts commit 49465bf41910e6b5868eb9ee4c7c11630714acfe.
Ying Chen 6 ani în urmă
părinte
comite
dbe2aeba9d
4 a modificat fișierele cu 15 adăugiri și 22 ștergeri
  1. 9 12
      tools/app_reg/app_reg.py
  2. 0 1
      tools/app_reg/common.py
  3. 0 1
      tools/app_reg/pth.py
  4. 6 8
      tools/app_reg/registry.py

+ 9 - 12
tools/app_reg/app_reg.py

@@ -37,10 +37,8 @@ Usage:
 Optional flags:
     --debug             Turns on debugging output
 """
-from __future__ import print_function
 
 
-from builtins import str
 import getopt
 import logging
 import os
@@ -51,7 +49,6 @@ import build
 import common
 import pth
 import registry
-from functools import reduce
 
 PROG_NAME = sys.argv[0]
 
@@ -70,8 +67,8 @@ def usage(msg=None):
   """Print the usage with an optional message. And exit."""
   global __doc__
   if msg is not None:
-    print(msg, file=sys.stderr)
-  print(__doc__ % dict(PROG_NAME=PROG_NAME), file=sys.stderr)
+    print >>sys.stderr, msg
+  print >>sys.stderr, __doc__ % dict(PROG_NAME=PROG_NAME)
   sys.exit(1)
 
 
@@ -113,7 +110,7 @@ def _do_install_one(reg, app_loc, relative_path):
     # Relative to cwd.
     app_loc = os.path.realpath(app_loc)
     app_name, version, desc, author = get_app_info(app_loc)
-  except (ValueError, OSError) as ex:
+  except (ValueError, OSError), ex:
     LOG.error(ex)
     return False
 
@@ -171,7 +168,7 @@ def do_remove(app_name):
     pthfile.remove(app)
     pthfile.save()
     return True
-  except (OSError, SystemError) as ex:
+  except (OSError, SystemError), ex:
     LOG.error("Failed to update the .pth file. Please fix any problem and run "
               "`%s --sync'\n%s" % (PROG_NAME, ex))
     return False
@@ -190,7 +187,7 @@ def do_sync(reg=None):
 
     build.make_syncdb()
     return True
-  except (OSError, SystemError) as ex:
+  except (OSError, SystemError), ex:
     LOG.error("Failed to update the .pth file. Please fix any problem and run "
               "`%s --sync'\n%s" % (PROG_NAME, ex))
     return False
@@ -201,7 +198,7 @@ def do_collectstatic():
   try:
     build.make_collectstatic()
     return True
-  except (OSError, SystemError) as ex:
+  except (OSError, SystemError), ex:
     LOG.error("Failed to collect the static files. Please fix any problem and run "
               "`%s --collectstatic'\n%s" % (PROG_NAME, ex))
     return False
@@ -216,7 +213,7 @@ def main():
     opts, tail = getopt.getopt(sys.argv[1:],
                                'ir:lds',
                                ('install', 'remove=', 'list', 'debug', 'sync'))
-  except getopt.GetoptError as ex:
+  except getopt.GetoptError, ex:
     usage(str(ex))
 
   def verify_action(current, new_val):
@@ -243,8 +240,8 @@ def main():
   if action == DO_INSTALL:
     # ['..', '--relative-paths', 'a', 'b'] => True
     # ['..', 'a', 'b'] -> False
-    relative_paths = reduce(lambda accum, x: accum or x, [x in ['--relative-paths'] for x in tail])
-    app_loc_list = [x for x in tail if x not in ['--relative-paths']]
+    relative_paths = reduce(lambda accum, x: accum or x, map(lambda x: x in ['--relative-paths'], tail))
+    app_loc_list = filter(lambda x: x not in ['--relative-paths'], tail)
   elif len(tail) != 0:
     usage("Unknown trailing arguments: %s" % ' '.join(tail))
 

+ 0 - 1
tools/app_reg/common.py

@@ -15,7 +15,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from past.builtins import cmp
 import glob
 import logging
 import os

+ 0 - 1
tools/app_reg/pth.py

@@ -19,7 +19,6 @@
 Tools to manipulate the .pth file in the virtualenv.
 """
 
-from builtins import object
 import glob
 import logging
 import os

+ 6 - 8
tools/app_reg/registry.py

@@ -19,8 +19,6 @@
 Registry for the applications
 """
 
-from past.builtins import cmp
-from builtins import object
 import glob
 import logging
 import os
@@ -58,7 +56,7 @@ class AppRegistry(object):
   def _write(self, path):
     """Write out the registry to the given path"""
     outfile = file(path, 'w')
-    json.dump(list(self._apps.values()), outfile, cls=AppJsonEncoder, indent=2)
+    json.dump(self._apps.values(), outfile, cls=AppJsonEncoder, indent=2)
     outfile.close()
 
   def contains(self, app):
@@ -100,7 +98,7 @@ class AppRegistry(object):
 
   def get_all_apps(self):
     """get_all_apps() -> List of HueApp"""
-    return list(self._apps.values())
+    return self._apps.values()
 
   def save(self):
     """Save and write out the registry"""
@@ -191,7 +189,7 @@ class HueApp(object):
           if not os.path.exists(cur):
             os.unlink(link_name)
             LOG.warn("Removing broken link: %s" % (link_name,))
-        except OSError as ex:
+        except OSError, ex:
           LOG.warn("Error checking for existing link %s: %s" % (link_name, ex))
 
       # Actually install the link
@@ -199,12 +197,12 @@ class HueApp(object):
         os.symlink(target, link_name)
         LOG.info('Symlink config %s -> %s' % (link_name, target))
         installed.append(link_name)
-      except OSError as ex:
+      except OSError, ex:
         LOG.error("Failed to symlink %s to %s: %s" % (target, link_name, ex))
         for lnk in installed:
           try:
             os.unlink(lnk)
-          except OSError as ex2:
+          except OSError, ex2:
             LOG.error("Failed to cleanup link %s: %s" % (link_name, ex2))
         return False
     return True
@@ -227,7 +225,7 @@ class HueApp(object):
         try:
           os.unlink(path)
           LOG.info('Remove config symlink %s -> %s' % (path, target))
-        except OSError as ex:
+        except OSError, ex:
           LOG.error("Failed to remove configuration link %s: %s" % (path, ex))
           return False
     return True