changeset 531:60c345d19daf

PEP-8 cleanup of skellington bits in root
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 11 Feb 2012 12:00:19 +0200
parents fe51223e0c8d
children 02cf5537d74e
files create-upload.py pyweek-upload.py setup.py
diffstat 3 files changed, 129 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/create-upload.py	Sat Feb 11 11:58:57 2012 +0200
+++ b/create-upload.py	Sat Feb 11 12:00:19 2012 +0200
@@ -20,7 +20,7 @@
 if len(sys.argv) != 2:
     print '''Usage: python %s <release filename-version>
 
-eg. python %s my_cool_game-1.0'''%(sys.argv[0], sys.argv[0])
+eg. python %s my_cool_game-1.0''' % (sys.argv[0], sys.argv[0])
     sys.exit()
 
 base = sys.argv[1]
@@ -36,6 +36,7 @@
     package.write(name, os.path.join(base, name))
 package.write('run_game.py', os.path.join(base, 'run_game.pyw'))
 
+
 # utility for adding subdirectories
 def add_files(generator):
     for dirpath, dirnames, filenames in generator:
@@ -44,10 +45,13 @@
                 dirnames.remove(name)
 
         for name in filenames:
-            if name.startswith('.'): continue
+            if name.startswith('.'):
+                continue
             suffix = os.path.splitext(name)[1]
-            if suffix in ('.pyc', '.pyo'): continue
-            if name[0] == '.': continue
+            if suffix in ('.pyc', '.pyo'):
+                continue
+            if name[0] == '.':
+                continue
             filename = os.path.join(dirpath, name)
             package.write(filename, os.path.join(base, filename))
 
--- a/pyweek-upload.py	Sat Feb 11 11:58:57 2012 +0200
+++ b/pyweek-upload.py	Sat Feb 11 12:00:19 2012 +0200
@@ -3,7 +3,14 @@
 
 Handles authentication and gives upload progress feedback.
 '''
-import sys, os, httplib, cStringIO, socket, time, getopt
+import cStringIO
+import getopt
+import httplib
+import os
+import socket
+import sys
+import time
+
 
 class Upload:
     def __init__(self, filename):
@@ -13,6 +20,7 @@
 sep_boundary = '\n--' + boundary
 end_boundary = sep_boundary + '--'
 
+
 def mimeEncode(data, sep_boundary=sep_boundary, end_boundary=end_boundary):
     '''Take the mapping of data and construct the body of a
     multipart/form-data message with it using the indicated boundaries.
@@ -20,16 +28,17 @@
     ret = cStringIO.StringIO()
     for key, value in data.items():
         # handle multiple entries for the same name
-        if type(value) != type([]): value = [value]
+        if type(value) != type([]):
+            value = [value]
         for value in value:
             ret.write(sep_boundary)
             if isinstance(value, Upload):
-                ret.write('\nContent-Disposition: form-data; name="%s"'%key)
+                ret.write('\nContent-Disposition: form-data; name="%s"' % key)
                 filename = os.path.basename(value.filename)
-                ret.write('; filename="%s"\n\n'%filename)
+                ret.write('; filename="%s"\n\n' % filename)
                 value = open(os.path.join(value.filename), "rb").read()
             else:
-                ret.write('\nContent-Disposition: form-data; name="%s"'%key)
+                ret.write('\nContent-Disposition: form-data; name="%s"' % key)
                 ret.write("\n\n")
                 value = str(value)
             ret.write(str(value))
@@ -38,11 +47,12 @@
     ret.write(end_boundary)
     return ret.getvalue()
 
+
 class Progress:
     def __init__(self, info, data):
         self.info = info
         self.tosend = len(data)
-        self.total = self.tosend/1024
+        self.total = self.tosend / 1024
         self.data = cStringIO.StringIO(data)
         self.start = self.now = time.time()
         self.sent = 0
@@ -51,12 +61,13 @@
         self.steptimes = []
         self.display()
 
-    def __iter__(self): return self
+    def __iter__(self):
+        return self
 
     def next(self):
         self.num += 1
         if self.sent >= self.tosend:
-            print self.info, 'done', ' '*(75-len(self.info)-6)
+            print self.info, 'done', ' ' * (75 - len(self.info) - 6)
             sys.stdout.flush()
             raise StopIteration
 
@@ -78,7 +89,7 @@
             self.steptimes.pop()
         steptime = sum(self.steptimes) / len(self.steptimes)
         self.now = now
-        eta = steptime * ((self.total - self.num)/self.stepsize)
+        eta = steptime * ((self.total - self.num) / self.stepsize)
 
         # tell it like it is (or might be)
         if now - self.start > 3:
@@ -87,17 +98,18 @@
             M = M % 60
             S = eta % 60
             if self.total:
-                s = '%s %2d%% (ETA %02d:%02d:%02d)'%(self.info,
+                s = '%s %2d%% (ETA %02d:%02d:%02d)' % (self.info,
                     self.num * 100. / self.total, H, M, S)
             else:
-                s = '%s 0%% (ETA %02d:%02d:%02d)'%(self.info, H, M, S)
+                s = '%s 0%% (ETA %02d:%02d:%02d)' % (self.info, H, M, S)
         elif self.total:
-            s = '%s %2d%%'%(self.info, self.num * 100. / self.total)
+            s = '%s %2d%%' % (self.info, self.num * 100. / self.total)
         else:
-            s = '%s %d done'%(self.info, self.num)
-        sys.stdout.write(s + ' '*(75-len(s)) + '\r')
+            s = '%s %d done' % (self.info, self.num)
+        sys.stdout.write(s + ' ' * (75-len(s)) + '\r')
         sys.stdout.flush()
 
+
 class progressHTTPConnection(httplib.HTTPConnection):
     def progress_send(self, str):
         """Send `str' to the server."""
@@ -116,12 +128,15 @@
                     raise
                 p.display()
 
+
 class progressHTTP(httplib.HTTP):
     _connection_class = progressHTTPConnection
+
     def _setup(self, conn):
         httplib.HTTP._setup(self, conn)
         self.progress_send = self._conn.progress_send
 
+
 def http_request(data, server, port, url):
     h = progressHTTP(server, port)
 
@@ -141,7 +156,9 @@
     f.close()
 
     print '%s %s'%(errcode, errmsg)
-    if response: print response
+    if response:
+        print response
+
 
 def usage():
     print '''This program is to be used to upload files to the PyWeek system.
@@ -178,15 +195,24 @@
     optional = {}
     url = None
     for opt, arg in optlist:
-        if opt == '-u': data['user'] = arg
-        elif opt == '-p': data['password'] = arg
-        elif opt == '-s': optional['is_screenshot'] = 'yes'
-        elif opt == '-f': optional['is_final'] = 'yes'
-        elif opt == '-d': data['description'] = arg
-        elif opt == '-c': data['content_file'] = Upload(arg)
-        elif opt == '-e': url = '/e/%s/oup/'%arg
-        elif opt == '-h': host = arg
-        elif opt == '-P': port = int(arg)
+        if opt == '-u':
+            data['user'] = arg
+        elif opt == '-p':
+            data['password'] = arg
+        elif opt == '-s':
+            optional['is_screenshot'] = 'yes'
+        elif opt == '-f':
+            optional['is_final'] = 'yes'
+        elif opt == '-d':
+            data['description'] = arg
+        elif opt == '-c':
+            data['content_file'] = Upload(arg)
+        elif opt == '-e':
+            url = '/e/%s/oup/'%arg
+        elif opt == '-h':
+            host = arg
+        elif opt == '-P':
+            port = int(arg)
 
     if len(data) < 4 or url is None:
         print 'Required argument missing'
--- a/setup.py	Sat Feb 11 11:58:57 2012 +0200
+++ b/setup.py	Sat Feb 11 12:00:19 2012 +0200
@@ -12,81 +12,83 @@
 except ImportError:
     pass
 
-setup   (   # Metadata
-            name = version.NAME,
-            version = version.VERSION_STR,
-            description = version.DESCRIPTION,
+setup(
+      # Metadata
+      name=version.NAME,
+      version=version.VERSION_STR,
+      description=version.DESCRIPTION,
 
-            author = version.AUTHOR_NAME,
-            author_email = version.AUTHOR_EMAIL,
+      author=version.AUTHOR_NAME,
+      author_email=version.AUTHOR_EMAIL,
 
-            maintainer = version.MAINTAINER_NAME,
-            maintainer_email = version.MAINTAINER_EMAIL,
+      maintainer=version.MAINTAINER_NAME,
+      maintainer_email=version.MAINTAINER_EMAIL,
 
-            # url = version.SOURCEFORGE_URL,
-            # download_url = version.PYPI_URL,
+      # url=version.SOURCEFORGE_URL,
+      # download_url=version.PYPI_URL,
 
-            license = version.LICENSE,
+      license=version.LICENSE,
 
-            classifiers = version.CLASSIFIERS,
+      classifiers=version.CLASSIFIERS,
 
-            platforms = version.PLATFORMS,
+      platforms=version.PLATFORMS,
 
-            # Dependencies
-            install_requires = version.INSTALL_REQUIRES,
+      # Dependencies
+      install_requires=version.INSTALL_REQUIRES,
 
-            # Files
-            packages = find_packages(),
-            scripts = ['run_game.py'],
+      # Files
+      packages=find_packages(),
+      scripts=['run_game.py'],
 
-            # py2exe
-            console = ['scripts/testconsole.py'],
-            windows = [{
-                'script': 'scripts/suspended.py',
-                'icon_resources': [(0, "Resources/icons/suspended_sentence.ico")],
-            }],
-            app = ['run_game.py'],
-            options = {
-            'py2exe': {
-                'skip_archive': 1,
-                'dist_dir': 'dist/suspended-sentence-%s' % version.VERSION_STR,
-                'packages': [
-                    'logging', 'encodings', 'gamelib',
-                ],
-                'includes': [
-                    # pygame
-                    'pygame', 'albow',
-                ],
-                'excludes': [
-                    'numpy',
-                ],
-                'ignores': [
-                    # all database modules
-                    'pgdb', 'Sybase', 'adodbapi',
-                    'kinterbasdb', 'psycopg', 'psycopg2', 'pymssql',
-                    'sapdb', 'pysqlite2', 'sqlite', 'sqlite3',
-                    'MySQLdb', 'MySQLdb.connections',
-                    'MySQLdb.constants.CR', 'MySQLdb.constants.ER',
-                    # old datetime equivalents
-                    'DateTime', 'DateTime.ISO',
-                    'mx', 'mx.DateTime', 'mx.DateTime.ISO',
-                    # email modules
-                    'email.Generator', 'email.Iterators', 'email.Utils',
-                ],
-            },
-            'py2app': {
-                'argv_emulation': 1,
-                'iconfile': 'Resources/icons/suspended_sentence.icns',
-#                 'dist_dir': 'dist/suspended-sentence-%s' % version.VERSION_STR,
-#                 'bdist_base': 'build/bdist',
-                'packages': [
-                    'logging', 'encodings', 'pygame', 'albow', 'gamelib', 'Resources',
-                ],
-                'excludes': ['numpy'],
-            }},
-            data_files = [
-                # 'COPYRIGHT',
-                'COPYING',
-                'README.txt',
-            ],
-        )
+      # py2exe
+      console=['scripts/testconsole.py'],
+      windows=[{
+          'script': 'scripts/suspended.py',
+          'icon_resources': [(0, "Resources/icons/suspended_sentence.ico")],
+      }],
+      app=['run_game.py'],
+      options={
+      'py2exe': {
+          'skip_archive': 1,
+          'dist_dir': 'dist/suspended-sentence-%s' % version.VERSION_STR,
+          'packages': [
+              'logging', 'encodings', 'gamelib',
+          ],
+          'includes': [
+              # pygame
+              'pygame', 'albow',
+          ],
+          'excludes': [
+              'numpy',
+          ],
+          'ignores': [
+              # all database modules
+              'pgdb', 'Sybase', 'adodbapi',
+              'kinterbasdb', 'psycopg', 'psycopg2', 'pymssql',
+              'sapdb', 'pysqlite2', 'sqlite', 'sqlite3',
+              'MySQLdb', 'MySQLdb.connections',
+              'MySQLdb.constants.CR', 'MySQLdb.constants.ER',
+              # old datetime equivalents
+              'DateTime', 'DateTime.ISO',
+              'mx', 'mx.DateTime', 'mx.DateTime.ISO',
+              # email modules
+              'email.Generator', 'email.Iterators', 'email.Utils',
+          ],
+      },
+      'py2app': {
+          'argv_emulation': 1,
+          'iconfile': 'Resources/icons/suspended_sentence.icns',
+#           'dist_dir': 'dist/suspended-sentence-%s' % version.VERSION_STR,
+#           'bdist_base': 'build/bdist',
+          'packages': [
+              'logging', 'encodings', 'pygame', 'albow', 'gamelib',
+              'Resources',
+          ],
+          'excludes': ['numpy'],
+      }},
+      data_files=[
+          # 'COPYRIGHT',
+          'COPYING',
+          'README.txt',
+      ],
+     )