[gnue] r9834 - trunk/gnue-common

[email protected]
Newsgroups gmane.comp.cms.gnue.cvs
Message-ID <[email protected]>
Author: johannes
Date: 2007-11-27 02:25:00 -0600 (Tue, 27 Nov 2007)
New Revision: 9834

Modified:
   trunk/gnue-common/setup.py
Log:
More work on PEP8


Modified: trunk/gnue-common/setup.py
===================================================================
--- trunk/gnue-common/setup.py	2007-11-27 08:19:36 UTC (rev 9833)
+++ trunk/gnue-common/setup.py	2007-11-27 08:25:00 UTC (rev 9834)
@@ -24,7 +24,6 @@
 # $Id$
 
 import sys
-import string
 import os
 
 from src.setup import ChangeLog
@@ -43,43 +42,43 @@
 # Note that you also have to add them to MANIFEST.in.
 # -----------------------------------------------------------------------------
 
-def set_params (params):
+def set_params(params):
 
     # The Work
-    params ["name"]             = PACKAGE.lower ()
-    params ["version"]          = VERSION
-    params ["description"]      = "GNU Enterprise Common Base"
-    params ["long_description"] = ""
-    params ["license"]          = "GPL"
+    params["name"]             = PACKAGE.lower()
+    params["version"]          = VERSION
+    params["description"]      = "GNU Enterprise Common Base"
+    params["long_description"] = ""
+    params["license"]          = "GPL"
 
     # The Author
-    params ["author"]       = "GNU Enterprise Team"
-    params ["author_email"] = "[email protected]"
-    params ["url"]          = "http://www.gnue.org"
+    params["author"]       = "GNU Enterprise Team"
+    params["author_email"] = "[email protected]"
+    params["url"]          = "http://www.gnue.org"
 
     # The Programs
-    params ["package_dir"] = {"gnue":        "module/base",
+    params["package_dir"] = {"gnue":        "module/base",
                               "gnue.common": "src"}
-    params ["scripts"] = ["scripts/gnue-schema"]
+    params["scripts"] = ["scripts/gnue-schema"]
 
     # The Data
     # TODO: get rid of setupext!
-    params ["data_files"] = \
-      [Data_Files (base_dir = 'install_data',
+    params["data_files"] = \
+      [Data_Files(base_dir = 'install_data',
                    copy_to = 'share/gnue',
                    template = ['recursive-include images *.png',
                                'recursive-include images *.bmp'],
                    preserve_path = 1),
-       Data_Files (base_dir = 'install_config',
+       Data_Files(base_dir = 'install_config',
                    copy_to = '',
                    template = ['recursive-include etc *',
                                'prune etc/.svn'],
                    preserve_path = 0),
-       Data_Files (base_dir = 'install_data',
+       Data_Files(base_dir = 'install_data',
                    copy_to = 'share/man/man1',
                    template = ['recursive-include doc/man *.1'],
                    preserve_path = 0),
-       Data_Files (base_dir = 'install_data',
+       Data_Files(base_dir = 'install_data',
                    copy_to = 'share/doc/gnue-common',
                    template = ['recursive-include doc *',
                                'prune doc/.svn',
@@ -95,46 +94,46 @@
 # FIXME: Better to build files in target directory directly.
 # -----------------------------------------------------------------------------
 
-def build_files (action):
+def build_files(action):
 
     if os.name == 'posix':
 
         # First check if we have everything installed we need to build the
         # distribution
 
-        if os.path.isdir ('po'):
+        if os.path.isdir('po'):
             # xgettext
-            if os.system ("pygettext --version > /dev/null") != 0:
+            if os.system("pygettext --version > /dev/null") != 0:
                 log.fatal("Could not find 'pygettext'. Strange.")
                 log.fatal("It should be included in the Python distribution.")
-                sys.exit (1)
+                sys.exit(1)
 
             # msgmerge
-            if os.system ("msgmerge --version > /dev/null") != 0:
+            if os.system("msgmerge --version > /dev/null") != 0:
                 log.fatal("Could not find 'msgmerge'. Please install Gettext.")
-                sys.exit (1)
+                sys.exit(1)
 
             # msgfmt
-            if os.system ("msgfmt --version > /dev/null") != 0:
+            if os.system("msgfmt --version > /dev/null") != 0:
                 log.fatal("Could not find 'msgfmt'. Please install Gettext.")
-                sys.exit (1)
+                sys.exit(1)
 
         # ---------------------------------------------------------------------
 
         if action == 'sdist':
             # build ChangeLog file
             log.info('building ChangeLog')
-            ChangeLog.build ()
+            ChangeLog.build()
 
         # build translations
-        if os.path.isdir ('po'):
+        if os.path.isdir('po'):
             log.info("building translations")
-            if os.system ("cd po && make gmo") != 0:
-                sys.exit (1)
+            if os.system("cd po && make gmo") != 0:
+                sys.exit(1)
 
     else:
         # on non posix systems just run msgfmt on existing .po files
-        if os.path.isdir ('po'):
+        if os.path.isdir('po'):
             # msgfmt.py
             argv0_path = os.path.dirname(os.path.abspath(sys.executable))
             sys.path.append(argv0_path + "\\tools\\i18n")
@@ -157,7 +156,7 @@
                 log.info("building translations")
                 for f in os.listdir('po'):
                     if f[-3:] == '.po':
-                        msgfmt.make ('po/'+f, 'po/'+f[:-3]+'.gmo')
+                        msgfmt.make('po/'+f, 'po/'+f[:-3]+'.gmo')
                         msgfmt.MESSAGES = {}
 
 # -----------------------------------------------------------------------------
@@ -181,7 +180,7 @@
 # Gets called on install.
 # -----------------------------------------------------------------------------
 
-def check_dependencies ():
+def check_dependencies():
 
     # seems like we have really none :-)
     pass
@@ -219,9 +218,9 @@
 installed, you may need to run:
 
 python2.3 setup.py
-  """ % string.split(sys.version)[0]
+  """ % sys.version.split()[0]
     print "-" * 70
-    sys.exit (1)
+    sys.exit(1)
 
 # -----------------------------------------------------------------------------
 # Find out whether or not to use our setup.cfg
@@ -230,18 +229,18 @@
 have_prefix = 0
 
 for arg in sys.argv:
-    if arg == "--prefix" or arg [:9] == "--prefix=" or \
-       arg == "--home"   or arg [:7] == "--home=":
+    if arg == "--prefix" or arg[:9] == "--prefix=" or \
+       arg == "--home"   or arg[:7] == "--home=":
         have_prefix = 1
 
 # Was setup.cfg specified on the command line?
 setupcfg = "setup.cfg.in"
 have_setupcfg = 0
 try:
-    index = sys.argv.index ('--setup-cfg')
-    setupcfg = sys.argv [index + 1]
-    sys.argv.pop (index)
-    sys.argv.pop (index)
+    index = sys.argv.index('--setup-cfg')
+    setupcfg = sys.argv[index + 1]
+    sys.argv.pop(index)
+    sys.argv.pop(index)
     have_setupcfg = 1
 
 except ValueError:
@@ -249,10 +248,10 @@
 
 if (os.name == "posix" and not have_prefix and "install" in sys.argv) \
    or have_setupcfg:
-    os.system ("cp %s setup.cfg" % setupcfg)
+    os.system("cp %s setup.cfg" % setupcfg)
 else:
     try:
-        os.remove ("setup.cfg")
+        os.remove("setup.cfg")
     except:
         pass
 
@@ -260,18 +259,18 @@
 # sdist: build files to be distributed first
 # =============================================================================
 
-class sdist (distutils.command.sdist.sdist):
+class sdist(distutils.command.sdist.sdist):
 
-    def run (self):
-        build_files ('sdist')
-        distutils.command.sdist.sdist.run (self)
+    def run(self):
+        build_files('sdist')
+        distutils.command.sdist.sdist.run(self)
 
     def prune_file_list(self):
         distutils.command.sdist.sdist.prune_file_list(self)
         self.filelist.exclude_pattern('*.dist_template', anchor=0)
 
-    def make_release_tree (self, base_dir, files):
-        distutils.command.sdist.sdist.make_release_tree (self, base_dir, files)
+    def make_release_tree(self, base_dir, files):
+        distutils.command.sdist.sdist.make_release_tree(self, base_dir, files)
         self.process_templates(base_dir)
         build_svnrev(os.path.join(base_dir, 'src', 'svnrev.py'))
 
@@ -332,14 +331,14 @@
 # build: if done from SVN, build files to be installed first
 # =============================================================================
 
-class build (distutils.command.build.build):
+class build(distutils.command.build.build):
 
-    def run (self):
+    def run(self):
         # TODO: Some smarter way to generate files. Maybe build a sdist object?
-        if not os.path.isfile ("PKG-INFO"):         # downloaded from SVN?
-            build_files ('build')
-        distutils.command.build.build.run (self)
-        if not os.path.isfile ("PKG-INFO"):
+        if not os.path.isfile("PKG-INFO"):         # downloaded from SVN?
+            build_files('build')
+        distutils.command.build.build.run(self)
+        if not os.path.isfile("PKG-INFO"):
             build_svnrev(os.path.join(self.build_lib, 'gnue', 'common',
                 'svnrev.py'))
 
@@ -347,14 +346,14 @@
 # install: New option, generate path dependent files
 # =============================================================================
 
-class install (distutils.command.install.install):
+class install(distutils.command.install.install):
 
     user_options = distutils.command.install.install.user_options
     i = 0
     for option in user_options:
         i = i + 1
-        if option [0] == "install-data=":
-            user_options.insert (i, ("install-config=", None,
+        if option[0] == "install-data=":
+            user_options.insert(i, ("install-config=", None,
                              "installation directory for configuration files"))
             break
 
@@ -362,50 +361,50 @@
     # Initalize options
     # -------------------------------------------------------------------------
 
-    def initialize_options (self):
-        distutils.command.install.install.initialize_options (self)
+    def initialize_options(self):
+        distutils.command.install.install.initialize_options(self)
         self.install_config = None
 
     # -------------------------------------------------------------------------
     # Finalize options (i.e. provide default if not set by user)
     # -------------------------------------------------------------------------
 
-    def finalize_options (self):
-        distutils.command.install.install.finalize_options (self)
+    def finalize_options(self):
+        distutils.command.install.install.finalize_options(self)
 
         # try to set a reasonable default for --install-config
         if self.install_config is None:
             if self.home == "/usr" or self.prefix == "/usr":
                 self.install_config = "/etc/gnue"
                 if self.root:
-                    self.install_config = change_root (self.root,
+                    self.install_config = change_root(self.root,
                             self.install_config)
             elif self.home == "/usr/local" or self.prefix == "/usr/local":
                 self.install_config = "/usr/local/etc/gnue"
                 if self.root:
-                    self.install_config = change_root (self.root,
+                    self.install_config = change_root(self.root,
                             self.install_config)
             elif self.home == "/opt/gnue" or self.prefix == "/opt/gnue":
                 self.install_config = "/etc/opt/gnue"
                 if self.root:
-                    self.install_config = change_root (self.root,
+                    self.install_config = change_root(self.root,
                             self.install_config)
             else:
-                self.install_config = os.path.join (self.install_data, "etc")
+                self.install_config = os.path.join(self.install_data, "etc")
 
     # -------------------------------------------------------------------------
     # Quote a path: remove --root and duplicate backslashes
     # -------------------------------------------------------------------------
 
-    def __quote (self, path):
+    def __quote(self, path):
         return self.__remove_root(path).replace("\\","\\\\")
 
-    def __remove_root (self, path):
+    def __remove_root(self, path):
         p = path
         if self.root:
             r = self.root
-            if r [-1] == os.sep:
-                r = r [:-1]
+            if r[-1] == os.sep:
+                r = r[:-1]
             p = p[len(r):]
         if p.endswith(os.sep):
             p = p[:-1]
@@ -415,32 +414,32 @@
     # Create gnue.pth
     # -------------------------------------------------------------------------
 
-    def __write_gnue_pth (self):
+    def __write_gnue_pth(self):
 
         # we need gnue.pth only if we don't install in python's search path
         if self.__remove_root(self.install_lib) not in sys.path:
             # where to install gnue.pth
-            site_dir = get_python_lib ()
+            site_dir = get_python_lib()
             if self.root:
         # add --root to target directory for gnue.py
-                site_dir = change_root (self.root, site_dir)
+                site_dir = change_root(self.root, site_dir)
 
             # especially if we have --root, the directory might not exist
-            if not os.path.isdir (site_dir):
-                os.makedirs (site_dir)
+            if not os.path.isdir(site_dir):
+                os.makedirs(site_dir)
 
             # now create the file
-            file = os.path.join (site_dir, "gnue.pth")
+            file = os.path.join(site_dir, "gnue.pth")
             log.info("trying to create %s" % file)
             try:
-                output = open (file, "w")
-                output.write (self.__quote (self.install_lib))
-                output.close ()
+                output = open(file, "w")
+                output.write(self.__quote(self.install_lib))
+                output.close()
                 # It worked. Turn off error message about installing into
                 # directory not in path.
-                sys.path.append (self.install_lib)
+                sys.path.append(self.install_lib)
                 # Record file
-                self.__outputs.append (file)
+                self.__outputs.append(file)
             except:
                 pass
 
@@ -448,90 +447,90 @@
     # Create paths.py
     # -------------------------------------------------------------------------
 
-    def __write_paths_py (self):
-        dir = os.path.join (self.install_lib, "gnue")
-        if not os.path.isdir (dir):
-            os.makedirs (dir)
-        file = os.path.join (dir, "paths.py")
+    def __write_paths_py(self):
+        dir = os.path.join(self.install_lib, "gnue")
+        if not os.path.isdir(dir):
+            os.makedirs(dir)
+        file = os.path.join(dir, "paths.py")
         log.info("creating %s" % file)
-        output = open (file, "w")
-        output.write ("# This file was generated during installation.\n")
-        output.write ("import os, sys\n")
-        output.write ("\n")
-        output.write ("lib     = \"%s\"\n" % self.__quote (self.install_lib))
-        output.write ("scripts = \"%s\"\n" % self.__quote (self.install_scripts))
-        output.write ("\n")
-        output.write ("############################\n")
-        output.write ("# This is a workaround for McMillan packaging!!!\n")
-        output.write ("# McMillan sets sys.frozen=1 in packaged exe file.\n")
-        output.write ("############################\n")
-        output.write ("if hasattr(sys, 'frozen') and sys.platform == 'win32':\n")
-        output.write ("  data    = os.path.dirname(os.path.dirname(sys.argv[0]))\n")
-        output.write ("  config  = os.path.join(data, 'etc')\n")
-        output.write ("else:\n")
-        output.write ("  data    = \"%s\"\n" % self.__quote (self.install_data))
-        output.write ("  config  = \"%s\"\n" % self.__quote (self.install_config))
-        output.close ()
+        output = open(file, "w")
+        output.write("# This file was generated during installation.\n")
+        output.write("import os, sys\n")
+        output.write("\n")
+        output.write("lib     = \"%s\"\n" % self.__quote(self.install_lib))
+        output.write("scripts = \"%s\"\n" % self.__quote(self.install_scripts))
+        output.write("\n")
+        output.write("############################\n")
+        output.write("# This is a workaround for McMillan packaging!!!\n")
+        output.write("# McMillan sets sys.frozen=1 in packaged exe file.\n")
+        output.write("############################\n")
+        output.write("if hasattr(sys, 'frozen') and sys.platform == 'win32':\n")
+        output.write("  data    = os.path.dirname(os.path.dirname(sys.argv[0]))\n")
+        output.write("  config  = os.path.join(data, 'etc')\n")
+        output.write("else:\n")
+        output.write("  data    = \"%s\"\n" % self.__quote(self.install_data))
+        output.write("  config  = \"%s\"\n" % self.__quote(self.install_config))
+        output.close()
         # Record file
-        self.__outputs.append (file)
+        self.__outputs.append(file)
 
     # -------------------------------------------------------------------------
     # Install translations by copying the files to the correct location
     # -------------------------------------------------------------------------
 
-    def __install_translations (self):
+    def __install_translations(self):
 
-        if os.path.isdir ('po'):
+        if os.path.isdir('po'):
             # copy files
-            for f in os.listdir ('po'):
-                if f [-4:] == '.gmo':
-                    src = os.path.join ('po', f)
-                    dst = os.path.join (self.install_data, 'share', 'locale',
+            for f in os.listdir('po'):
+                if f[-4:] == '.gmo':
+                    src = os.path.join('po', f)
+                    dst = os.path.join(self.install_data, 'share', 'locale',
                             f[:-4], 'LC_MESSAGES')
-                    self.mkpath (dst)
-                    dst = os.path.join (dst, PACKAGE.lower () + '.mo')
-                    self.copy_file (src, dst)
+                    self.mkpath(dst)
+                    dst = os.path.join(dst, PACKAGE.lower() + '.mo')
+                    self.copy_file(src, dst)
                     # Record file
-                    self.__outputs.append (dst)
+                    self.__outputs.append(dst)
 
     # -------------------------------------------------------------------------
     # install.run: generate and install path dependent files
     # -------------------------------------------------------------------------
 
-    def run (self):
-        check_dependencies ()
+    def run(self):
+        check_dependencies()
 
         self.__outputs = []
 
-        self.__write_gnue_pth ()
+        self.__write_gnue_pth()
 
-        self.__write_paths_py ()
+        self.__write_paths_py()
 
-        self.__install_translations ()
+        self.__install_translations()
 
-        distutils.command.install.install.run (self)
+        distutils.command.install.install.run(self)
 
     # -------------------------------------------------------------------------
     # install.get_outputs: list all installed files
     # -------------------------------------------------------------------------
 
-    def get_outputs (self):
-        return distutils.command.install.install.get_outputs (self) \
+    def get_outputs(self):
+        return distutils.command.install.install.get_outputs(self) \
                + self.__outputs
 
 # -----------------------------------------------------------------------------
 # Get all packages in a directory
 # -----------------------------------------------------------------------------
 
-def get_packages (directory, package):
-    content = os.listdir (directory)
+def get_packages(directory, package):
+    content = os.listdir(directory)
     result = []
     if "__init__.py" in content:
         result = [package]
         for name in content:
-            fullname = os.path.join (directory, name)
-            if os.path.isdir (fullname):
-                result = result + get_packages (fullname, package + "." + name)
+            fullname = os.path.join(directory, name)
+            if os.path.isdir(fullname):
+                result = result + get_packages(fullname, package + "." + name)
     return result
 
 # -----------------------------------------------------------------------------
@@ -540,36 +539,36 @@
 
 setup_params = {}
 
-set_params (setup_params)
+set_params(setup_params)
 
-if not setup_params.has_key ("packages"):
+if not setup_params.has_key("packages"):
     packages = []
-    for module, directory in setup_params["package_dir"].items ():
-        packages = packages + get_packages (directory, module)
-    setup_params ["packages"] = packages
+    for module, directory in setup_params["package_dir"].items():
+        packages = packages + get_packages(directory, module)
+    setup_params["packages"] = packages
 
-setup (name             = setup_params ["name"],
-       version          = setup_params ["version"],
-       description      = setup_params ["description"],
-       long_description = setup_params ["long_description"],
-       author           = setup_params ["author"],
-       author_email     = setup_params ["author_email"],
-       url              = setup_params ["url"],
-       license          = setup_params ["license"],
-       packages         = setup_params ["packages"],
-       package_dir      = setup_params ["package_dir"],
-       scripts          = setup_params ["scripts"],
-       data_files       = setup_params ["data_files"],
+setup(name             = setup_params["name"],
+      version          = setup_params["version"],
+      description      = setup_params["description"],
+      long_description = setup_params["long_description"],
+      author           = setup_params["author"],
+      author_email     = setup_params["author_email"],
+      url              = setup_params["url"],
+      license          = setup_params["license"],
+      packages         = setup_params["packages"],
+      package_dir      = setup_params["package_dir"],
+      scripts          = setup_params["scripts"],
+      data_files       = setup_params["data_files"],
 
-       # Override certain command classes with our own ones
-       cmdclass = {"sdist": sdist,
-                   "build": build,
-                   "install": install,
-                   "install_data": install_Data_Files})
+      # Override certain command classes with our own ones
+      cmdclass = {"sdist": sdist,
+                  "build": build,
+                  "install": install,
+                  "install_data": install_Data_Files})
 
 # -----------------------------------------------------------------------------
 # Clean up
 # -----------------------------------------------------------------------------
 
-if os.path.isfile ("setup.cfg"):
-    os.remove ("setup.cfg")
+if os.path.isfile("setup.cfg"):
+    os.remove("setup.cfg")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.