From 295084976bf3c0aa445205f85bf7e1286fa7945e Mon Sep 17 00:00:00 2001 From: mdipierro Date: Fri, 19 Oct 2012 14:22:42 -0500 Subject: [PATCH] pep8 in scripts/*.py --- VERSION | 2 +- scripts/autoroutes.py | 52 +- scripts/bench.py | 7 +- scripts/cleancss.py | 25 +- scripts/cleanhtml.py | 79 +-- scripts/cleanjs.py | 18 +- scripts/contentparser.py | 12 +- scripts/cpdb.py | 804 +++++++++++++++-------------- scripts/cpplugin.py | 34 +- scripts/dbsessions2trash.py | 9 +- scripts/dict_diff.py | 27 +- scripts/extract_mysql_models.py | 92 ++-- scripts/extract_pgsql_models.py | 56 +- scripts/fixws.py | 11 +- scripts/layout_make.py | 52 +- scripts/make_min_web2py.py | 59 ++- scripts/rmorphans.py | 12 +- scripts/sessions2trash.py | 34 +- scripts/standalone_exe_cxfreeze.py | 60 +-- scripts/sync_languages.py | 20 +- scripts/tickets2db.py | 8 +- scripts/tickets2email.py | 4 +- scripts/update_web2py.py | 14 +- scripts/zip_static_files.py | 10 +- 24 files changed, 781 insertions(+), 720 deletions(-) diff --git a/VERSION b/VERSION index 4e40b239..ca1f2b22 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.1.1 (2012-10-19 14:13:30) dev +Version 2.1.1 (2012-10-19 14:22:39) dev diff --git a/scripts/autoroutes.py b/scripts/autoroutes.py index c1119ab0..aaef82dd 100644 --- a/scripts/autoroutes.py +++ b/scripts/autoroutes.py @@ -40,48 +40,58 @@ domain3.com /app3/defcon3 ''' if not config.strip(): try: - config_file = open('routes.conf','r') + config_file = open('routes.conf', 'r') try: config = config_file.read() finally: config_file.close() except: - config='' + config = '' + def auto_in(apps): routes = [ - ('/robots.txt','/welcome/static/robots.txt'), - ('/favicon.ico','/welcome/static/favicon.ico'), - ('/admin$anything','/admin$anything'), - ] - for domain,path in [x.strip().split() for x in apps.split('\n') if x.strip() and not x.strip().startswith('#')]: - if not path.startswith('/'): path = '/'+path - if path.endswith('/'): path = path[:-1] + ('/robots.txt', '/welcome/static/robots.txt'), + ('/favicon.ico', '/welcome/static/favicon.ico'), + ('/admin$anything', '/admin$anything'), + ] + for domain, path in [x.strip().split() for x in apps.split('\n') if x.strip() and not x.strip().startswith('#')]: + if not path.startswith('/'): + path = '/' + path + if path.endswith('/'): + path = path[:-1] app = path.split('/')[1] routes += [ - ('.*:https?://(.*\.)?%s:$method /' % domain,'%s' % path), - ('.*:https?://(.*\.)?%s:$method /static/$anything' % domain,'/%s/static/$anything' % app), - ('.*:https?://(.*\.)?%s:$method /appadmin/$anything' % domain,'/%s/appadmin/$anything' % app), - ('.*:https?://(.*\.)?%s:$method /$anything' % domain,'%s/$anything' % path), - ] + ('.*:https?://(.*\.)?%s:$method /' % domain, '%s' % path), + ('.*:https?://(.*\.)?%s:$method /static/$anything' % + domain, '/%s/static/$anything' % app), + ('.*:https?://(.*\.)?%s:$method /appadmin/$anything' % + domain, '/%s/appadmin/$anything' % app), + ('.*:https?://(.*\.)?%s:$method /$anything' % + domain, '%s/$anything' % path), + ] return routes + def auto_out(apps): routes = [] - for domain,path in [x.strip().split() for x in apps.split('\n') if x.strip() and not x.strip().startswith('#')]: - if not path.startswith('/'): path = '/'+path - if path.endswith('/'): path = path[:-1] + for domain, path in [x.strip().split() for x in apps.split('\n') if x.strip() and not x.strip().startswith('#')]: + if not path.startswith('/'): + path = '/' + path + if path.endswith('/'): + path = path[:-1] app = path.split('/')[1] routes += [ - ('/%s/static/$anything' % app,'/static/$anything'), + ('/%s/static/$anything' % app, '/static/$anything'), ('/%s/appadmin/$anything' % app, '/appadmin/$anything'), ('%s/$anything' % path, '/$anything'), - ] + ] return routes routes_in = auto_in(config) routes_out = auto_out(config) + def __routes_doctest(): ''' Dummy function for doctesting autoroutes.py. @@ -128,7 +138,8 @@ if __name__ == '__main__': try: import gluon.main except ImportError: - import sys, os + import sys + import os os.chdir(os.path.dirname(os.path.dirname(__file__))) sys.path.append(os.path.dirname(os.path.dirname(__file__))) import gluon.main @@ -138,4 +149,3 @@ if __name__ == '__main__': import doctest doctest.testmod() - diff --git a/scripts/bench.py b/scripts/bench.py index ffb98452..75e1917b 100644 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -5,11 +5,12 @@ import urllib2 n = int(sys.argv[1]) url = sys.argv[2] -headers = {"Accept-Language" : "en" } +headers = {"Accept-Language": "en"} req = urllib2.Request(url, None, headers) t0 = time.time() for k in xrange(n): data = urllib2.urlopen(req).read() -print (time.time()-t0)/n -if n==1: print data +print (time.time() - t0) / n +if n == 1: + print data diff --git a/scripts/cleancss.py b/scripts/cleancss.py index 7380773f..c2d2a113 100755 --- a/scripts/cleancss.py +++ b/scripts/cleancss.py @@ -8,26 +8,25 @@ filename = sys.argv[1] datafile = open(filename, 'r') try: - data = '\n'+datafile.read() + data = '\n' + datafile.read() finally: datafile.close() SPACE = '\n ' if '-n' in sys.argv[1:] else ' ' -data = re.compile('(?.*)').sub('/* \g */',data) +data = re.compile('(?.*)').sub('/* \g */', data) data = re.compile('[ ]+').sub(' ', data) -data = re.compile('\s*{\s*').sub(' {'+SPACE, data) -data = re.compile('\s*;\s*').sub(';'+SPACE, data) +data = re.compile('\s*{\s*').sub(' {' + SPACE, data) +data = re.compile('\s*;\s*').sub(';' + SPACE, data) data = re.compile(',\s*').sub(', ', data) -data = re.compile('\s*\*/\s*').sub('*/'+SPACE, data) -data = re.compile('\s*}\s*').sub(SPACE+'}\n', data) +data = re.compile('\s*\*/\s*').sub('*/' + SPACE, data) +data = re.compile('\s*}\s*').sub(SPACE + '}\n', data) data = re.compile('\n\s*\n').sub('\n', data) -data = re.compile(';\s+/\*').sub('; /*',data) -data = re.compile('\*/\s+/\*').sub(' ',data) +data = re.compile(';\s+/\*').sub('; /*', data) +data = re.compile('\*/\s+/\*').sub(' ', data) data = re.compile('[ ]+\n').sub('\n', data) -data = re.compile('\n\s*/[\*]+(?P.*?)[\*]+/',re.DOTALL).sub( - '\n/*\g*/\n',data) -data = re.compile('[ \t]+(?P\S.+?){').sub('\g{',data) -data = data.replace('}','}\n') +data = re.compile('\n\s*/[\*]+(?P.*?)[\*]+/', re.DOTALL).sub( + '\n/*\g*/\n', data) +data = re.compile('[ \t]+(?P\S.+?){').sub('\g{', data) +data = data.replace('}', '}\n') print data - diff --git a/scripts/cleanhtml.py b/scripts/cleanhtml.py index 0bbfe823..e0df55b2 100755 --- a/scripts/cleanhtml.py +++ b/scripts/cleanhtml.py @@ -1,51 +1,55 @@ import sys import re + def cleancss(text): - text=re.compile('\s+').sub(' ', text) - text=re.compile('\s*(?P,|:)\s*').sub('\g ', text) - text=re.compile('\s*;\s*').sub(';\n ', text) - text=re.compile('\s*\{\s*').sub(' {\n ', text) - text=re.compile('\s*\}\s*').sub('\n}\n\n', text) + text = re.compile('\s+').sub(' ', text) + text = re.compile('\s*(?P,|:)\s*').sub('\g ', text) + text = re.compile('\s*;\s*').sub(';\n ', text) + text = re.compile('\s*\{\s*').sub(' {\n ', text) + text = re.compile('\s*\}\s*').sub('\n}\n\n', text) return text + def cleanhtml(text): - text=text.lower() - r=re.compile('\', re.DOTALL) - scripts=r.findall(text) - text=r.sub('