clach04 avatar clach04 committed 3612515

pep8 cleanup of code and generated setup.py.

Comments (0)

Files changed (1)

poachplatelib/package.py

 CONFIG_LOC = os.path.expanduser('~/.config/poachplate.ini')
 YEAR = datetime.date.today().strftime('%Y')
 
+
 class _Unset(object): 
     """ We need a value to represent unset for configuration.  None
     doesn't really work since the user might want None to be a valid
     """
     pass
 
-def cascade_value(opt=None, opt_name=None, # optparse
-                  env_name=None, # os.environ
-                  cfg=None, cfg_section=None, cfg_name=None, # ConfigParser
+
+def cascade_value(opt=None, opt_name=None,  # optparse
+                  env_name=None,  # os.environ
+                  cfg=None, cfg_section=None, cfg_name=None,  # ConfigParser
                   default=None):
     """
     Allow a posix style cascading config
     if not os.path.exists(CONFIG_LOC):
         create_file(fout(CONFIG_LOC), DEFAULT_CONFIG)
 
+
 def create_file(fout, content=None):
     if not content is None:
         fout.write(content)
 
+
 def fout(name):
     out = open(name, 'w')
     return out
 
+
 class Package(object):
     def __init__(self, name, libname=None, scriptname=None, opt=None, cfg_loc=None):
         self.name = name
         pep8name = self.name.lower()
-        self.libname = libname or pep8name+'lib'
+        self.libname = libname or pep8name + 'lib'
 
         for filename in [pep8name, self.libname]:
             if not filename[0].isalpha():
-                raise NameError, '%s should start with alpha character' % filename
+                raise NameError('%s should start with alpha character' % filename)
         self.scriptname = scriptname or pep8name
 
         cfg = None
      
     def generate(self):
         if os.path.exists(self.name):
-            raise NameError, '%s project directory already exists' % self.name
+            raise NameError('%s project directory already exists' % self.name)
 
         os.makedirs(self.name)
         cur_dir = os.getcwd()
         os.chdir(self.name)
 
-        script_copyright = '# Copyright (c) %(year)s %(author)s' % {'author':self.author,'year':YEAR}
+        script_copyright = '# Copyright (c) %(year)s %(author)s' % {'author': self.author, 'year': YEAR}
 
         os.makedirs(self.libname)        
         create_file(fout(os.path.join(self.libname, '__init__.py')), '''#!/usr/bin/env python
 if __name__ == '__main__':
     sys.exit(main(sys.argv))
 
-''' % {'script_copyright':script_copyright})
+''' % {'script_copyright': script_copyright})
 
         self.gen_meta(script_copyright)
         self.gen_setup(script_copyright)
 
 if __name__ == '__main__':
     unittest.main()
-""" %{'libname':self.libname,
-      'libnamecap':self.libname.capitalize(),
-      'script_copyright':script_copyright})
-        
+"""  % {'libname': self.libname,
+      'libnamecap': self.libname.capitalize(),
+      'script_copyright': script_copyright})
 
     def gen_script(self, script_copyright):
         """
         sys.stderr.write('%%s\\n'%%str(e))
         sys.exit(1)  
 
-""" % {'libname':self.libname,
-       'script_copyright':script_copyright})
+""" % {'libname': self.libname,
+       'script_copyright': script_copyright})
         
     def gen_meta(self, script_copyright):
-        create_file(fout(os.path.join(self.libname, 'meta.py')),"""%(script_copyright)s
+        create_file(fout(os.path.join(self.libname, 'meta.py')), """%(script_copyright)s
 
 __version__ = '%(version)s'
 __author__ = '%(author)s'
 __email__ = '%(email)s'
-""" % {'version':self.version,
-       'author':self.author,
-       'email':self.email,
-       'script_copyright':script_copyright})
+""" % {'version': self.version,
+       'author': self.author,
+       'email': self.email,
+       'script_copyright': script_copyright})
 
     def gen_setup(self, script_copyright):
         if self.scriptname:
-            script = """scripts=['bin/%(file)s'],""" % {'file':self.scriptname}
+            script = """scripts=['bin/%(file)s'],""" % {'file': self.scriptname}
         else:
             script = ''
 
       author=meta.__author__,
       description='FILL IN',
       %(script)s
-      package_dir={'%(libname)s':'%(libname)s'},
+      package_dir={'%(libname)s': '%(libname)s'},
       packages=['%(libname)s'],
 )
-''' % {'name':self.name,
-       'script':script,
-       'libname':self.libname,
-       'script_copyright':script_copyright})
+''' % {'name': self.name,
+       'script': script,
+       'libname': self.libname,
+       'script_copyright': script_copyright})
 
 
 def main(prog_args):
         p.generate()
     else:
         parser.print_help()
-        
-    
+
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv) or 0)
-    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.