pep8 in scripts/*.py
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.1.1 (2012-10-19 14:13:30) dev
|
Version 2.1.1 (2012-10-19 14:22:39) dev
|
||||||
|
|||||||
+19
-9
@@ -48,6 +48,7 @@ if not config.strip():
|
|||||||
except:
|
except:
|
||||||
config = ''
|
config = ''
|
||||||
|
|
||||||
|
|
||||||
def auto_in(apps):
|
def auto_in(apps):
|
||||||
routes = [
|
routes = [
|
||||||
('/robots.txt', '/welcome/static/robots.txt'),
|
('/robots.txt', '/welcome/static/robots.txt'),
|
||||||
@@ -55,22 +56,30 @@ def auto_in(apps):
|
|||||||
('/admin$anything', '/admin$anything'),
|
('/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('#')]:
|
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 not path.startswith('/'):
|
||||||
if path.endswith('/'): path = path[:-1]
|
path = '/' + path
|
||||||
|
if path.endswith('/'):
|
||||||
|
path = path[:-1]
|
||||||
app = path.split('/')[1]
|
app = path.split('/')[1]
|
||||||
routes += [
|
routes += [
|
||||||
('.*:https?://(.*\.)?%s:$method /' % domain, '%s' % path),
|
('.*:https?://(.*\.)?%s:$method /' % domain, '%s' % path),
|
||||||
('.*:https?://(.*\.)?%s:$method /static/$anything' % domain,'/%s/static/$anything' % app),
|
('.*:https?://(.*\.)?%s:$method /static/$anything' %
|
||||||
('.*:https?://(.*\.)?%s:$method /appadmin/$anything' % domain,'/%s/appadmin/$anything' % app),
|
domain, '/%s/static/$anything' % app),
|
||||||
('.*:https?://(.*\.)?%s:$method /$anything' % domain,'%s/$anything' % path),
|
('.*:https?://(.*\.)?%s:$method /appadmin/$anything' %
|
||||||
|
domain, '/%s/appadmin/$anything' % app),
|
||||||
|
('.*:https?://(.*\.)?%s:$method /$anything' %
|
||||||
|
domain, '%s/$anything' % path),
|
||||||
]
|
]
|
||||||
return routes
|
return routes
|
||||||
|
|
||||||
|
|
||||||
def auto_out(apps):
|
def auto_out(apps):
|
||||||
routes = []
|
routes = []
|
||||||
for domain, path in [x.strip().split() for x in apps.split('\n') if x.strip() and not x.strip().startswith('#')]:
|
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 not path.startswith('/'):
|
||||||
if path.endswith('/'): path = path[:-1]
|
path = '/' + path
|
||||||
|
if path.endswith('/'):
|
||||||
|
path = path[:-1]
|
||||||
app = path.split('/')[1]
|
app = path.split('/')[1]
|
||||||
routes += [
|
routes += [
|
||||||
('/%s/static/$anything' % app, '/static/$anything'),
|
('/%s/static/$anything' % app, '/static/$anything'),
|
||||||
@@ -82,6 +91,7 @@ def auto_out(apps):
|
|||||||
routes_in = auto_in(config)
|
routes_in = auto_in(config)
|
||||||
routes_out = auto_out(config)
|
routes_out = auto_out(config)
|
||||||
|
|
||||||
|
|
||||||
def __routes_doctest():
|
def __routes_doctest():
|
||||||
'''
|
'''
|
||||||
Dummy function for doctesting autoroutes.py.
|
Dummy function for doctesting autoroutes.py.
|
||||||
@@ -128,7 +138,8 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
import gluon.main
|
import gluon.main
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import sys, os
|
import sys
|
||||||
|
import os
|
||||||
os.chdir(os.path.dirname(os.path.dirname(__file__)))
|
os.chdir(os.path.dirname(os.path.dirname(__file__)))
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
||||||
import gluon.main
|
import gluon.main
|
||||||
@@ -138,4 +149,3 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -12,4 +12,5 @@ t0 = time.time()
|
|||||||
for k in xrange(n):
|
for k in xrange(n):
|
||||||
data = urllib2.urlopen(req).read()
|
data = urllib2.urlopen(req).read()
|
||||||
print (time.time() - t0) / n
|
print (time.time() - t0) / n
|
||||||
if n==1: print data
|
if n == 1:
|
||||||
|
print data
|
||||||
|
|||||||
@@ -30,4 +30,3 @@ data = re.compile('[ \t]+(?P<a>\S.+?){').sub('\g<a>{',data)
|
|||||||
data = data.replace('}', '}\n')
|
data = data.replace('}', '}\n')
|
||||||
|
|
||||||
print data
|
print data
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def cleancss(text):
|
def cleancss(text):
|
||||||
text = re.compile('\s+').sub(' ', text)
|
text = re.compile('\s+').sub(' ', text)
|
||||||
text = re.compile('\s*(?P<a>,|:)\s*').sub('\g<a> ', text)
|
text = re.compile('\s*(?P<a>,|:)\s*').sub('\g<a> ', text)
|
||||||
@@ -9,6 +10,7 @@ def cleancss(text):
|
|||||||
text = re.compile('\s*\}\s*').sub('\n}\n\n', text)
|
text = re.compile('\s*\}\s*').sub('\n}\n\n', text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def cleanhtml(text):
|
def cleanhtml(text):
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
r = re.compile('\<script.+?/script\>', re.DOTALL)
|
r = re.compile('\<script.+?/script\>', re.DOTALL)
|
||||||
@@ -32,7 +34,8 @@ def cleanhtml(text):
|
|||||||
if not line[:2] == '</' and line[-1:] == '>' and \
|
if not line[:2] == '</' and line[-1:] == '>' and \
|
||||||
not line[-2:] in ['/>', '->']: indent = indent + 1
|
not line[-2:] in ['/>', '->']: indent = indent + 1
|
||||||
text = '\n'.join(newlines)
|
text = '\n'.join(newlines)
|
||||||
text=re.compile('\<div(?P<a>( .+)?)\>\s+\</div\>').sub('<div\g<a>></div>',text)
|
text = re.compile(
|
||||||
|
'\<div(?P<a>( .+)?)\>\s+\</div\>').sub('<div\g<a>></div>', text)
|
||||||
text = re.compile('\<a(?P<a>( .+)?)\>\s+(?P<b>[\w\s\(\)\/]+?)\s+\</a\>').sub('<a\g<a>>\g<b></a>', text)
|
text = re.compile('\<a(?P<a>( .+)?)\>\s+(?P<b>[\w\s\(\)\/]+?)\s+\</a\>').sub('<a\g<a>>\g<b></a>', text)
|
||||||
text = re.compile('\<b(?P<a>( .+)?)\>\s+(?P<b>[\w\s\(\)\/]+?)\s+\</b\>').sub('<b\g<a>>\g<b></b>', text)
|
text = re.compile('\<b(?P<a>( .+)?)\>\s+(?P<b>[\w\s\(\)\/]+?)\s+\</b\>').sub('<b\g<a>>\g<b></b>', text)
|
||||||
text = re.compile('\<i(?P<a>( .+)?)\>\s+(?P<b>[\w\s\(\)\/]+?)\s+\</i\>').sub('<i\g<a>>\g<b></i>', text)
|
text = re.compile('\<i(?P<a>( .+)?)\>\s+(?P<b>[\w\s\(\)\/]+?)\s+\</i\>').sub('<i\g<a>>\g<b></i>', text)
|
||||||
@@ -46,6 +49,7 @@ def cleanhtml(text):
|
|||||||
text = text.replace('<style />', cleancss(style), 1)
|
text = text.replace('<style />', cleancss(style), 1)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def read_file(filename):
|
def read_file(filename):
|
||||||
f = open(filename, 'r')
|
f = open(filename, 'r')
|
||||||
try:
|
try:
|
||||||
@@ -58,4 +62,3 @@ if file[-4:]=='.css':
|
|||||||
print cleancss(read_file(file))
|
print cleancss(read_file(file))
|
||||||
if file[-5:] == '.html':
|
if file[-5:] == '.html':
|
||||||
print cleanhtml(read_file(file))
|
print cleanhtml(read_file(file))
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def cleanjs(text):
|
def cleanjs(text):
|
||||||
text = re.sub('\s*}\s*', '\n}\n', text)
|
text = re.sub('\s*}\s*', '\n}\n', text)
|
||||||
text = re.sub('\s*{\s*', ' {\n', text)
|
text = re.sub('\s*{\s*', ' {\n', text)
|
||||||
@@ -14,4 +15,3 @@ def cleanjs(text):
|
|||||||
if rline:
|
if rline:
|
||||||
pass
|
pass
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|||||||
@@ -72,14 +72,15 @@ if __name__ == '__main__':
|
|||||||
sys.stdout.write('Checking freedesktop.org database version:')
|
sys.stdout.write('Checking freedesktop.org database version:')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
search = re.search('(?P<url>http://freedesktop.org/.+?/shared-mime-info-(?P<version>.+?)\.tar\.(?P<type>[gb]z2?))',
|
search = re.search(
|
||||||
|
'(?P<url>http://freedesktop.org/.+?/shared-mime-info-(?P<version>.+?)\.tar\.(?P<type>[gb]z2?))',
|
||||||
urllib.urlopen('http://www.freedesktop.org/wiki/Software/shared-mime-info').read())
|
urllib.urlopen('http://www.freedesktop.org/wiki/Software/shared-mime-info').read())
|
||||||
url = search.group('url')
|
url = search.group('url')
|
||||||
assert url != None
|
assert url is not None
|
||||||
nversion = search.group('version')
|
nversion = search.group('version')
|
||||||
assert nversion != None
|
assert nversion is not None
|
||||||
ftype = search.group('type')
|
ftype = search.group('type')
|
||||||
assert ftype != None
|
assert ftype is not None
|
||||||
sys.stdout.write('\t[OK] version %s\n' % nversion)
|
sys.stdout.write('\t[OK] version %s\n' % nversion)
|
||||||
except:
|
except:
|
||||||
sys.stdout.write('\t[ERROR] unknown version\n')
|
sys.stdout.write('\t[ERROR] unknown version\n')
|
||||||
@@ -129,4 +130,3 @@ if __name__ == '__main__':
|
|||||||
sys.stdout.write('\t\t\t[OK] done\n')
|
sys.stdout.write('\t\t\t[OK] done\n')
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.stdout.write('\t\t\t[ERROR] %s\n' % e)
|
sys.stdout.write('\t\t\t[ERROR] %s\n' % e)
|
||||||
|
|
||||||
|
|||||||
+130
-120
@@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
import os,sys
|
import os
|
||||||
|
import sys
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import string
|
import string
|
||||||
import argparse
|
import argparse
|
||||||
import cStringIO,operator
|
import cStringIO
|
||||||
|
import operator
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import math
|
import math
|
||||||
@@ -15,6 +17,7 @@ try:
|
|||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
print('gluon path not found')
|
print('gluon path not found')
|
||||||
|
|
||||||
|
|
||||||
class refTable(object):
|
class refTable(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.columns = None
|
self.columns = None
|
||||||
@@ -24,8 +27,8 @@ class refTable(object):
|
|||||||
return "{0}".format(' | '.join([string.join(string.strip('**{0}**'.format(item)),
|
return "{0}".format(' | '.join([string.join(string.strip('**{0}**'.format(item)),
|
||||||
'') for item in colHeader]))
|
'') for item in colHeader]))
|
||||||
|
|
||||||
|
def wrapTable(
|
||||||
def wrapTable(self,rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
|
self, rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
|
||||||
separateRows=False, prefix='', postfix='', wrapfunc=lambda x: x):
|
separateRows=False, prefix='', postfix='', wrapfunc=lambda x: x):
|
||||||
|
|
||||||
def rowWrapper(row):
|
def rowWrapper(row):
|
||||||
@@ -40,7 +43,8 @@ class refTable(object):
|
|||||||
rowList gives like newRows but
|
rowList gives like newRows but
|
||||||
formatted like [[w, x, y, z]]
|
formatted like [[w, x, y, z]]
|
||||||
---'''
|
---'''
|
||||||
rowList = [[substr or '' for substr in item] for item in map(None,*newRows)]
|
rowList = [[substr or '' for substr in item]
|
||||||
|
for item in map(None, *newRows)]
|
||||||
return rowList
|
return rowList
|
||||||
|
|
||||||
logicalRows = [rowWrapper(row) for row in rows]
|
logicalRows = [rowWrapper(row) for row in rows]
|
||||||
@@ -48,27 +52,24 @@ class refTable(object):
|
|||||||
columns = map(None, *reduce(operator.add, logicalRows))
|
columns = map(None, *reduce(operator.add, logicalRows))
|
||||||
self.columns = columns
|
self.columns = columns
|
||||||
|
|
||||||
maxWidths = [max(\
|
maxWidths = [max(
|
||||||
[len(str\
|
[len(str
|
||||||
(item)) for \
|
(item)) for
|
||||||
item in column]\
|
item in column]
|
||||||
) for column \
|
) for column
|
||||||
in columns]
|
in columns]
|
||||||
|
|
||||||
rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) + \
|
rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) +
|
||||||
len(delim) * (len(maxWidths) - 1))
|
len(delim) * (len(maxWidths) - 1))
|
||||||
|
|
||||||
justify = {'center'\
|
justify = {'center': str
|
||||||
:str\
|
|
||||||
.center,
|
.center,
|
||||||
'right'\
|
'right': str
|
||||||
:str\
|
|
||||||
.rjust,
|
.rjust,
|
||||||
'left'\
|
'left': str.
|
||||||
:str.\
|
ljust
|
||||||
ljust\
|
}[justify
|
||||||
}[justify\
|
.lower(
|
||||||
.lower(\
|
|
||||||
)]
|
)]
|
||||||
|
|
||||||
output = cStringIO.StringIO()
|
output = cStringIO.StringIO()
|
||||||
@@ -79,40 +80,41 @@ class refTable(object):
|
|||||||
for physicalRows in logicalRows:
|
for physicalRows in logicalRows:
|
||||||
for row in physicalRows:
|
for row in physicalRows:
|
||||||
print >> output,\
|
print >> output,\
|
||||||
prefix + delim.join([\
|
prefix + delim.join([
|
||||||
justify(str(item),width) for (\
|
justify(str(item), width) for (
|
||||||
item,width) in zip(row,maxWidths)]\
|
item, width) in zip(row, maxWidths)]
|
||||||
) + postfix
|
) + postfix
|
||||||
|
|
||||||
if separateRows or hasHeader:
|
if separateRows or hasHeader:
|
||||||
print >> output, rowSeparator; hasHeader=False
|
print >> output, rowSeparator
|
||||||
|
hasHeader = False
|
||||||
return output.getvalue()
|
return output.getvalue()
|
||||||
|
|
||||||
def wrap_onspace(self, text, width):
|
def wrap_onspace(self, text, width):
|
||||||
return reduce(lambda line, word, width=width: '{0}{1}{2}'\
|
return reduce(lambda line, word, width=width: '{0}{1}{2}'
|
||||||
.format(line\
|
.format(line, ' \n'[(len(
|
||||||
,' \n'[(len(\
|
line[line.rfind('\n'
|
||||||
line[line.rfind('\n'\
|
) + 1:]) + len(
|
||||||
) + 1:]) + len(\
|
word.split('\n', 1)[0]) >=
|
||||||
word.split('\n',1)[0]) >=\
|
|
||||||
width)], word), text.split(' '))
|
width)], word), text.split(' '))
|
||||||
|
|
||||||
def wrap_onspace_strict(self, text, width):
|
def wrap_onspace_strict(self, text, width):
|
||||||
wordRegex = re.compile(r'\S{' + str(width) + r',}')
|
wordRegex = re.compile(r'\S{' + str(width) + r',}')
|
||||||
return self.wrap_onspace(\
|
return self.wrap_onspace(
|
||||||
wordRegex.sub(\
|
wordRegex.sub(
|
||||||
lambda m: self.\
|
lambda m: self.
|
||||||
wrap_always(\
|
wrap_always(
|
||||||
m.group(),width),text\
|
m.group(), width), text
|
||||||
), width)
|
), width)
|
||||||
|
|
||||||
def wrap_always(self, text, width):
|
def wrap_always(self, text, width):
|
||||||
return '\n'.join(\
|
return '\n'.join(
|
||||||
[ text[width*i:width*(i+1\
|
[text[width * i:width * (i + 1
|
||||||
)] for i in xrange(\
|
)] for i in xrange(
|
||||||
int(math.ceil(1.*len(\
|
int(math.ceil(1. * len(
|
||||||
text) / width)))])
|
text) / width)))])
|
||||||
|
|
||||||
|
|
||||||
class tableHelper():
|
class tableHelper():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.oTable = refTable()
|
self.oTable = refTable()
|
||||||
@@ -122,8 +124,10 @@ class tableHelper():
|
|||||||
|
|
||||||
def getTable_noWrap(self, data, header=None):
|
def getTable_noWrap(self, data, header=None):
|
||||||
rows = self.getAsRows(data)
|
rows = self.getAsRows(data)
|
||||||
if header is not None:hRows = [header]+rows
|
if header is not None:
|
||||||
else:hRows = rows
|
hRows = [header] + rows
|
||||||
|
else:
|
||||||
|
hRows = rows
|
||||||
table = self.oTable.wrapTable(hRows, hasHeader=True)
|
table = self.oTable.wrapTable(hRows, hasHeader=True)
|
||||||
return table
|
return table
|
||||||
|
|
||||||
@@ -131,19 +135,15 @@ class tableHelper():
|
|||||||
wrapper = None
|
wrapper = None
|
||||||
if len(wrapStyle) > 1:
|
if len(wrapStyle) > 1:
|
||||||
rows = self.getAsRows(data)
|
rows = self.getAsRows(data)
|
||||||
if header is not None:hRows = [header]+rows
|
if header is not None:
|
||||||
else:hRows = rows
|
hRows = [header] + rows
|
||||||
|
else:
|
||||||
|
hRows = rows
|
||||||
|
|
||||||
for wrapper in (self.oTable.wrap_always,
|
for wrapper in (self.oTable.wrap_always,
|
||||||
self.oTable.wrap_onspace,
|
self.oTable.wrap_onspace,
|
||||||
self.oTable.wrap_onspace_strict):
|
self.oTable.wrap_onspace_strict):
|
||||||
return self.oTable.wrapTable(hRows\
|
return self.oTable.wrapTable(hRows, hasHeader=True, separateRows=True, prefix='| ', postfix=' |', wrapfunc=lambda x:
|
||||||
,hasHeader=True\
|
|
||||||
,separateRows=True\
|
|
||||||
,prefix='| '\
|
|
||||||
,postfix=' |'\
|
|
||||||
,wrapfunc\
|
|
||||||
=lambda x:\
|
|
||||||
wrapper(x, width))
|
wrapper(x, width))
|
||||||
else:
|
else:
|
||||||
return self.getTable_noWrap(data, header)
|
return self.getTable_noWrap(data, header)
|
||||||
@@ -164,10 +164,12 @@ class console:
|
|||||||
if "cmd_" == i[:4]:
|
if "cmd_" == i[:4]:
|
||||||
cmd = i.split("cmd_")[1].lower()
|
cmd = i.split("cmd_")[1].lower()
|
||||||
self.commands[cmd] = getattr(self, i)
|
self.commands[cmd] = getattr(self, i)
|
||||||
try:self.commandSort.append((int(self\
|
try:
|
||||||
.commands[cmd].__doc__.split(\
|
self.commandSort.append((int(self
|
||||||
|
.commands[cmd].__doc__.split(
|
||||||
"|")[0]), cmd))
|
"|")[0]), cmd))
|
||||||
except:pass
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
self.commandSort.sort()
|
self.commandSort.sort()
|
||||||
self.commandSort = [i[1] for i in self.commandSort]
|
self.commandSort = [i[1] for i in self.commandSort]
|
||||||
@@ -194,15 +196,19 @@ class console:
|
|||||||
self.execCommand(command)
|
self.execCommand(command)
|
||||||
except:
|
except:
|
||||||
self.execute(command)
|
self.execute(command)
|
||||||
except KeyboardInterrupt:break
|
except KeyboardInterrupt:
|
||||||
except EOFError:break
|
break
|
||||||
except Exception,a:self.printError (a)
|
except EOFError:
|
||||||
|
break
|
||||||
|
except Exception, a:
|
||||||
|
self.printError(a)
|
||||||
print ("\r\n\r\nBye!...")
|
print ("\r\n\r\nBye!...")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def printError(self, err):
|
def printError(self, err):
|
||||||
sys.stderr.write("Error: {0}\r\n".format(str(err),))
|
sys.stderr.write("Error: {0}\r\n".format(str(err),))
|
||||||
if self.var_DEBUG:pass
|
if self.var_DEBUG:
|
||||||
|
pass
|
||||||
|
|
||||||
def execute(self, cmd):
|
def execute(self, cmd):
|
||||||
try:
|
try:
|
||||||
@@ -222,23 +228,24 @@ class console:
|
|||||||
try:
|
try:
|
||||||
invalidParams.append(i)
|
invalidParams.append(i)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
raise Exception, 'invalid parameter\n{0}'.format(i)
|
raise Exception('invalid parameter\n{0}'.format(i))
|
||||||
else:
|
else:
|
||||||
if 'file=' in i:
|
if 'file=' in i:
|
||||||
file=os.path.abspath(string.strip(string.split(i,'=')[1]))
|
file = os.path.abspath(string.strip(string.split(
|
||||||
|
i, '=')[1]))
|
||||||
if 'fields=' in i:
|
if 'fields=' in i:
|
||||||
for field in string.split(string.split(i, '=')[1], ','):
|
for field in string.split(string.split(i, '=')[1], ','):
|
||||||
if field in self.db[table].fields:
|
if field in self.db[table].fields:
|
||||||
fields.append(string.strip(field))
|
fields.append(string.strip(field))
|
||||||
|
|
||||||
if len(invalidParams) > 0:
|
if len(invalidParams) > 0:
|
||||||
print('the following parameter(s) is not valid\n{0}'.format(\
|
print('the following parameter(s) is not valid\n{0}'.format(
|
||||||
string.join(invalidParams, ',')))
|
string.join(invalidParams, ',')))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.cmd_table(table, file, fields)
|
self.cmd_table(table, file, fields)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print('could not generate table for table {0}\n{1}'\
|
print('could not generate table for table {0}\n{1}'
|
||||||
.format(table, err))
|
.format(table, err))
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print('sorry, can not do that!\n{0}'.format(err))
|
print('sorry, can not do that!\n{0}'.format(err))
|
||||||
@@ -252,11 +259,13 @@ class console:
|
|||||||
def execCommand(self, cmd):
|
def execCommand(self, cmd):
|
||||||
words = cmd.split(" ")
|
words = cmd.split(" ")
|
||||||
words = [i for i in words if i]
|
words = [i for i in words if i]
|
||||||
if not words:return
|
if not words:
|
||||||
|
return
|
||||||
cmd, parameters = words[0].lower(), words[1:]
|
cmd, parameters = words[0].lower(), words[1:]
|
||||||
|
|
||||||
if not cmd in self.commands:
|
if not cmd in self.commands:
|
||||||
raise Exception("Command {0} not found. Try 'help'\r\n".format(cmd))
|
raise Exception(
|
||||||
|
"Command {0} not found. Try 'help'\r\n".format(cmd))
|
||||||
|
|
||||||
self.commands[cmd](*parameters)
|
self.commands[cmd](*parameters)
|
||||||
|
|
||||||
@@ -327,32 +336,36 @@ style choices:
|
|||||||
data = string.join(rows_data, '\n')
|
data = string.join(rows_data, '\n')
|
||||||
dataTable = oTable.getTable_Wrap(data, tableStyle, table_fields)
|
dataTable = oTable.getTable_Wrap(data, tableStyle, table_fields)
|
||||||
print('TABLE {0}\n{1}'.format(table, dataTable))
|
print('TABLE {0}\n{1}'.format(table, dataTable))
|
||||||
if file!=None:
|
if file is not None:
|
||||||
try:
|
try:
|
||||||
tail, head = os.path.split(file)
|
tail, head = os.path.split(file)
|
||||||
try:
|
try:
|
||||||
os.makedirs(tail)
|
os.makedirs(tail)
|
||||||
except:'do nothing, folders exist'
|
except:
|
||||||
|
'do nothing, folders exist'
|
||||||
oFile = open(file, 'w')
|
oFile = open(file, 'w')
|
||||||
oFile.write('TABLE: {0}\n{1}'.format(table, dataTable))
|
oFile.write('TABLE: {0}\n{1}'.format(table, dataTable))
|
||||||
oFile.close()
|
oFile.close()
|
||||||
print('{0} has been created and populated with all available data from table {1}\n'.format(file, table))
|
print('{0} has been created and populated with all available data from table {1}\n'.format(file, table))
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print("EXCEPTION: could not create table {0}\n{1}".format(table,err))
|
print("EXCEPTION: could not create table {0}\n{1}".format(
|
||||||
|
table, err))
|
||||||
else:
|
else:
|
||||||
print('the following fields are not valid [{0}]'.format(string.join(filedNotFound,',')))
|
print('the following fields are not valid [{0}]'.format(
|
||||||
|
string.join(filedNotFound, ',')))
|
||||||
|
|
||||||
def cmd_help(self, *args):
|
def cmd_help(self, *args):
|
||||||
'''-3|help|Show's help'''
|
'''-3|help|Show's help'''
|
||||||
alldata = []
|
alldata = []
|
||||||
lengths = []
|
lengths = []
|
||||||
|
|
||||||
for i in self.commandSort:alldata.append(\
|
for i in self.commandSort:
|
||||||
|
alldata.append(
|
||||||
self.commands[i].__doc__.split("|")[1:])
|
self.commands[i].__doc__.split("|")[1:])
|
||||||
|
|
||||||
for i in alldata:
|
for i in alldata:
|
||||||
if len(i) > len(lengths):
|
if len(i) > len(lengths):
|
||||||
for j in range(len(i)\
|
for j in range(len(i)
|
||||||
- len(lengths)):
|
- len(lengths)):
|
||||||
lengths.append(0)
|
lengths.append(0)
|
||||||
|
|
||||||
@@ -364,9 +377,11 @@ style choices:
|
|||||||
|
|
||||||
print ("-" * (lengths[0] + lengths[1] + 4))
|
print ("-" * (lengths[0] + lengths[1] + 4))
|
||||||
for i in alldata:
|
for i in alldata:
|
||||||
print (("%-"+str(lengths[0])+"s - %-"+str(lengths[1])+"s") % (i[0],i[1]))
|
print (("%-" + str(lengths[0]) + "s - %-" + str(
|
||||||
|
lengths[1]) + "s") % (i[0], i[1]))
|
||||||
if len(i) > 2:
|
if len(i) > 2:
|
||||||
for j in i[2:]:print (("%"+str(lengths[0]+9)+"s* %s") % (" ",j))
|
for j in i[2:]: print (("%" + str(lengths[
|
||||||
|
0] + 9) + "s* %s") % (" ", j))
|
||||||
print
|
print
|
||||||
|
|
||||||
def cmd_vars(self, *args):
|
def cmd_vars(self, *args):
|
||||||
@@ -376,7 +391,8 @@ style choices:
|
|||||||
value = self.parfmt(repr(getattr(self, j)), 52)
|
value = self.parfmt(repr(getattr(self, j)), 52)
|
||||||
print ("| %20s | %52s |" % (i, value[0]))
|
print ("| %20s | %52s |" % (i, value[0]))
|
||||||
for k in value[1:]: print ("| %20s | %52s |" % ("", k))
|
for k in value[1:]: print ("| %20s | %52s |" % ("", k))
|
||||||
if len(value)>1:print("| %20s | %52s |" % ("",""))
|
if len(value) > 1:
|
||||||
|
print("| %20s | %52s |" % ("", ""))
|
||||||
print ("-" * 79)
|
print ("-" * 79)
|
||||||
|
|
||||||
def parfmt(self, txt, width):
|
def parfmt(self, txt, width):
|
||||||
@@ -384,7 +400,8 @@ style choices:
|
|||||||
pos = 0
|
pos = 0
|
||||||
while True:
|
while True:
|
||||||
a = txt[pos:pos + width]
|
a = txt[pos:pos + width]
|
||||||
if not a:break
|
if not a:
|
||||||
|
break
|
||||||
res.append(a)
|
res.append(a)
|
||||||
pos += width
|
pos += width
|
||||||
return res
|
return res
|
||||||
@@ -415,6 +432,7 @@ style choices:
|
|||||||
---'''
|
---'''
|
||||||
print '\n' * numlines
|
print '\n' * numlines
|
||||||
|
|
||||||
|
|
||||||
class dalShell(console):
|
class dalShell(console):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
@@ -423,6 +441,7 @@ class dalShell(console):
|
|||||||
console.__init__(self, prompt=">>> ", banner='dal interactive shell')
|
console.__init__(self, prompt=">>> ", banner='dal interactive shell')
|
||||||
self.execCmd(db)
|
self.execCmd(db)
|
||||||
|
|
||||||
|
|
||||||
class setCopyDB():
|
class setCopyDB():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
'''---
|
'''---
|
||||||
@@ -454,16 +473,19 @@ class setCopyDB():
|
|||||||
if self.dalPath is not None:
|
if self.dalPath is not None:
|
||||||
global DAL
|
global DAL
|
||||||
sys.path.append(self.dalPath)
|
sys.path.append(self.dalPath)
|
||||||
mDal=__import__('dal',globals={},locals={},fromlist=['DAL'],level=0)
|
mDal = __import__(
|
||||||
|
'dal', globals={}, locals={}, fromlist=['DAL'], level=0)
|
||||||
DAL = mDal.DAL
|
DAL = mDal.DAL
|
||||||
return mDal
|
return mDal
|
||||||
|
|
||||||
def instDB(self, storageFolder, storageConnectionString, autoImport):
|
def instDB(self, storageFolder, storageConnectionString, autoImport):
|
||||||
self.db=DAL(storageConnectionString,folder=os.path.abspath(storageFolder),auto_import=autoImport)
|
self.db = DAL(storageConnectionString, folder=os.path.abspath(
|
||||||
|
storageFolder), auto_import=autoImport)
|
||||||
return self.db
|
return self.db
|
||||||
|
|
||||||
def delete_DB_tables(self, storageFolder, storageType):
|
def delete_DB_tables(self, storageFolder, storageType):
|
||||||
print 'delete_DB_tablesn\n\t{0}\n\t{1}'.format(storageFolder,storageType)
|
print 'delete_DB_tablesn\n\t{0}\n\t{1}'.format(
|
||||||
|
storageFolder, storageType)
|
||||||
dataFiles = [storageType, "sql.log"]
|
dataFiles = [storageType, "sql.log"]
|
||||||
try:
|
try:
|
||||||
for f in os.listdir(storageFolder):
|
for f in os.listdir(storageFolder):
|
||||||
@@ -473,7 +495,8 @@ class setCopyDB():
|
|||||||
print('deleted {0}'.format(fTable))
|
print('deleted {0}'.format(fTable))
|
||||||
for dFile in dataFiles:
|
for dFile in dataFiles:
|
||||||
os.remove("{0}/{1}".format(storageFolder, dFile))
|
os.remove("{0}/{1}".format(storageFolder, dFile))
|
||||||
print('deleted {0}'.format("{0}/{1}".format(storageFolder,dFile)))
|
print('deleted {0}'.format(
|
||||||
|
"{0}/{1}".format(storageFolder, dFile)))
|
||||||
except Exception, errObj:
|
except Exception, errObj:
|
||||||
print(str(errObj))
|
print(str(errObj))
|
||||||
|
|
||||||
@@ -495,12 +518,14 @@ class setCopyDB():
|
|||||||
print('EXCEPTION: {0}'.format(err))
|
print('EXCEPTION: {0}'.format(err))
|
||||||
|
|
||||||
def copyDB(self):
|
def copyDB(self):
|
||||||
other_db=DAL("{0}://{1}".format(self.targetdbType,self.targetdbName),folder=self.targetFolder)
|
other_db = DAL("{0}://{1}".format(
|
||||||
|
self.targetdbType, self.targetdbName), folder=self.targetFolder)
|
||||||
|
|
||||||
print 'creating tables...'
|
print 'creating tables...'
|
||||||
|
|
||||||
for table in self.db:
|
for table in self.db:
|
||||||
other_db.define_table(table._tablename,*[field for field in table])
|
other_db.define_table(
|
||||||
|
table._tablename, *[field for field in table])
|
||||||
'''
|
'''
|
||||||
should there be an option to truncAte target DB?
|
should there be an option to truncAte target DB?
|
||||||
if yes, then change args to allow for choice
|
if yes, then change args to allow for choice
|
||||||
@@ -521,7 +546,8 @@ class setCopyDB():
|
|||||||
|
|
||||||
def createfolderPath(self, folder):
|
def createfolderPath(self, folder):
|
||||||
try:
|
try:
|
||||||
if folder!=None:os.makedirs(folder)
|
if folder is not None:
|
||||||
|
os.makedirs(folder)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -539,15 +565,9 @@ samplecmd line:\n\
|
|||||||
-f ./blueLite/db_storage -i -y sqlite://storage.sqlite -Y sqlite://storage2.sqlite -d ./blueLite/pyUtils/sql/blueSQL -t True',
|
-f ./blueLite/db_storage -i -y sqlite://storage.sqlite -Y sqlite://storage2.sqlite -d ./blueLite/pyUtils/sql/blueSQL -t True',
|
||||||
epilog='')
|
epilog='')
|
||||||
reqGroup = parser.add_argument_group('Required arguments')
|
reqGroup = parser.add_argument_group('Required arguments')
|
||||||
reqGroup.add_argument('-f','--sourceFolder'\
|
reqGroup.add_argument('-f', '--sourceFolder', required=True, help="path to the 'source' folder of the 'source' DB")
|
||||||
,required=True\
|
reqGroup.add_argument('-F', '--targetFolder', required=False, help="path to the 'target' folder of the 'target' DB")
|
||||||
,help="path to the 'source' folder of the 'source' DB")
|
reqGroup.add_argument('-y', '--sourceConnectionString', required=True, help="source db connection string ()\n\
|
||||||
reqGroup.add_argument('-F','--targetFolder'\
|
|
||||||
,required=False\
|
|
||||||
,help="path to the 'target' folder of the 'target' DB")
|
|
||||||
reqGroup.add_argument('-y','--sourceConnectionString'\
|
|
||||||
,required=True\
|
|
||||||
,help="source db connection string ()\n\
|
|
||||||
------------------------------------------------\n\
|
------------------------------------------------\n\
|
||||||
\
|
\
|
||||||
sqlite://storage.db\n\
|
sqlite://storage.db\n\
|
||||||
@@ -561,13 +581,10 @@ ingres://username:password@localhost/test\n\
|
|||||||
informix://username:password@test\n\
|
informix://username:password@test\n\
|
||||||
\
|
\
|
||||||
------------------------------------------------")
|
------------------------------------------------")
|
||||||
reqGroup.add_argument('-Y','--targetConnectionString'\
|
reqGroup.add_argument('-Y', '--targetConnectionString', required=True,
|
||||||
,required=True\
|
help="target db type (sqlite,mySql,etc.)")
|
||||||
,help="target db type (sqlite,mySql,etc.)")
|
|
||||||
autoImpGroup = parser.add_argument_group('optional args (auto_import)')
|
autoImpGroup = parser.add_argument_group('optional args (auto_import)')
|
||||||
autoImpGroup.add_argument('-a','--autoimport'\
|
autoImpGroup.add_argument('-a', '--autoimport', required=False, help='set to True to bypass loading of the model')
|
||||||
,required=False\
|
|
||||||
,help='set to True to bypass loading of the model')
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -584,25 +601,13 @@ informix://username:password@test\n\
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
miscGroup = parser.add_argument_group('optional args/tasks')
|
miscGroup = parser.add_argument_group('optional args/tasks')
|
||||||
miscGroup.add_argument('-i','--interactive'\
|
miscGroup.add_argument('-i', '--interactive', required=False, action='store_true', help='run in interactive mode')
|
||||||
,required=False\
|
miscGroup.add_argument(
|
||||||
,action='store_true'\
|
'-d', '--dal', required=False, help='path to dal.py')
|
||||||
,help='run in interactive mode')
|
miscGroup.add_argument('-t', '--truncate', choices=['True', 'False'], help='delete the records but *not* the table of the SOURCE DB')
|
||||||
miscGroup.add_argument('-d','--dal'\
|
miscGroup.add_argument('-b', '--tables', required=False, type=list, help='optional list (comma delimited) of SOURCE tables to truncate, defaults to all')
|
||||||
,required=False\
|
miscGroup.add_argument('-c', '--clean', required=False, help='delete the DB,tables and the log file, WARNING: this is unrecoverable')
|
||||||
,help='path to dal.py')
|
|
||||||
miscGroup.add_argument('-t','--truncate'\
|
|
||||||
,choices=['True','False']\
|
|
||||||
,help='delete the records but *not* the table of the SOURCE DB')
|
|
||||||
miscGroup.add_argument('-b','--tables'\
|
|
||||||
,required=False\
|
|
||||||
,type=list\
|
|
||||||
,help='optional list (comma delimited) of SOURCE tables to truncate, defaults to all')
|
|
||||||
miscGroup.add_argument('-c','--clean'\
|
|
||||||
,required=False\
|
|
||||||
,help='delete the DB,tables and the log file, WARNING: this is unrecoverable')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
db = None
|
db = None
|
||||||
@@ -623,27 +628,31 @@ informix://username:password@test\n\
|
|||||||
if args.dal:
|
if args.dal:
|
||||||
try:
|
try:
|
||||||
autoImport = True
|
autoImport = True
|
||||||
if args.autoimport:autoImport=args.autoimport
|
if args.autoimport:
|
||||||
|
autoImport = args.autoimport
|
||||||
#sif not DAL in globals:
|
#sif not DAL in globals:
|
||||||
#if not sys.path.__contains__():
|
#if not sys.path.__contains__():
|
||||||
oCopy.dalPath = args.dal
|
oCopy.dalPath = args.dal
|
||||||
mDal = oCopy._getDal()
|
mDal = oCopy._getDal()
|
||||||
db=oCopy.instDB(args.sourceFolder,args.sourceConnectionString,autoImport)
|
db = oCopy.instDB(args.sourceFolder, args.sourceConnectionString,
|
||||||
|
autoImport)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print('EXCEPTION: could not set DAL\n{0}'.format(err))
|
print('EXCEPTION: could not set DAL\n{0}'.format(err))
|
||||||
if args.truncate:
|
if args.truncate:
|
||||||
try:
|
try:
|
||||||
if args.truncate:
|
if args.truncate:
|
||||||
if args.tables:tables=string.split(string.strip(args.tables),',')
|
if args.tables:
|
||||||
else:oCopy.truncatetables([])
|
tables = string.split(string.strip(args.tables), ',')
|
||||||
|
else:
|
||||||
|
oCopy.truncatetables([])
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print('EXCEPTION: could not truncate tables\n{0}'.format(err))
|
print('EXCEPTION: could not truncate tables\n{0}'.format(err))
|
||||||
try:
|
try:
|
||||||
if args.clean:oCopy.delete_DB_tables(oCopy.targetFolder,oCopy.targetType)
|
if args.clean:
|
||||||
|
oCopy.delete_DB_tables(oCopy.targetFolder, oCopy.targetType)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print('EXCEPTION: could not clean db\n{0}'.format(err))
|
print('EXCEPTION: could not clean db\n{0}'.format(err))
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
*** goes with -m/-M options... removed for now
|
*** goes with -m/-M options... removed for now
|
||||||
|
|
||||||
@@ -665,7 +674,8 @@ target model: {1}\n\
|
|||||||
oCopy.createfolderPath(oCopy.sourceFolder)
|
oCopy.createfolderPath(oCopy.sourceFolder)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print('EXCEPTION: could not create folder path\n{0}'.format(err))
|
print('EXCEPTION: could not create folder path\n{0}'.format(err))
|
||||||
else:oCopy.dbStorageFolder=os.path.abspath(os.getcwd())
|
else:
|
||||||
|
oCopy.dbStorageFolder = os.path.abspath(os.getcwd())
|
||||||
if args.targetFolder:
|
if args.targetFolder:
|
||||||
try:
|
try:
|
||||||
oCopy.targetFolder = os.path.abspath(args.targetFolder)
|
oCopy.targetFolder = os.path.abspath(args.targetFolder)
|
||||||
|
|||||||
+12
-6
@@ -1,9 +1,14 @@
|
|||||||
import sys, glob, os, shutil
|
import sys
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
name = sys.argv[1]
|
name = sys.argv[1]
|
||||||
app = sys.argv[2]
|
app = sys.argv[2]
|
||||||
dest = sys.argv[3]
|
dest = sys.argv[3]
|
||||||
a=glob.glob('applications/%(app)s/*/plugin_%(name)s.*' % dict(app=app,name=name))
|
a = glob.glob(
|
||||||
b=glob.glob('applications/%(app)s/*/plugin_%(name)s/*' % dict(app=app,name=name))
|
'applications/%(app)s/*/plugin_%(name)s.*' % dict(app=app, name=name))
|
||||||
|
b = glob.glob(
|
||||||
|
'applications/%(app)s/*/plugin_%(name)s/*' % dict(app=app, name=name))
|
||||||
|
|
||||||
for f in a:
|
for f in a:
|
||||||
print 'cp %s ...' % f,
|
print 'cp %s ...' % f,
|
||||||
@@ -14,8 +19,10 @@ for f in b:
|
|||||||
print 'cp %s ...' % f,
|
print 'cp %s ...' % f,
|
||||||
path = f.split('/')
|
path = f.split('/')
|
||||||
for i in range(3, len(path)):
|
for i in range(3, len(path)):
|
||||||
try: os.mkdir(os.path.join('applications',dest,*path[2:i]))
|
try:
|
||||||
except: pass
|
os.mkdir(os.path.join('applications', dest, *path[2:i]))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
path = os.path.join('applications', dest, *f.split('/')[2:])
|
path = os.path.join('applications', dest, *f.split('/')[2:])
|
||||||
if os.path.isdir(f):
|
if os.path.isdir(f):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
@@ -23,4 +30,3 @@ for f in b:
|
|||||||
else:
|
else:
|
||||||
shutil.copyfile(f, path)
|
shutil.copyfile(f, path)
|
||||||
print 'done'
|
print 'done'
|
||||||
|
|
||||||
|
|||||||
@@ -23,4 +23,3 @@ while 1: # Infinite loop
|
|||||||
db.commit() # Write changes to database
|
db.commit() # Write changes to database
|
||||||
|
|
||||||
sleep(SLEEP_MINUTES * 60)
|
sleep(SLEEP_MINUTES * 60)
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import getopt
|
|||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
"""Parse the arguments and start the main process."""
|
"""Parse the arguments and start the main process."""
|
||||||
try:
|
try:
|
||||||
@@ -40,16 +41,19 @@ def main(argv):
|
|||||||
else:
|
else:
|
||||||
exit_with_parsing_error()
|
exit_with_parsing_error()
|
||||||
|
|
||||||
|
|
||||||
def exit_with_parsing_error():
|
def exit_with_parsing_error():
|
||||||
"""Report invalid arguments and usage."""
|
"""Report invalid arguments and usage."""
|
||||||
print("Invalid argument(s).")
|
print("Invalid argument(s).")
|
||||||
usage()
|
usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
"""Display the documentation"""
|
"""Display the documentation"""
|
||||||
print(__doc__)
|
print(__doc__)
|
||||||
|
|
||||||
|
|
||||||
def get_dicts(dict_path1, dict_path2):
|
def get_dicts(dict_path1, dict_path2):
|
||||||
"""
|
"""
|
||||||
Parse the dictionaries.
|
Parse the dictionaries.
|
||||||
@@ -60,6 +64,7 @@ def get_dicts(dict_path1, dict_path2):
|
|||||||
|
|
||||||
return eval(open(dict_path1).read()), eval(open(dict_path2).read())
|
return eval(open(dict_path1).read()), eval(open(dict_path2).read())
|
||||||
|
|
||||||
|
|
||||||
def get_dict_names(dict1_path, dict2_path):
|
def get_dict_names(dict1_path, dict2_path):
|
||||||
"""
|
"""
|
||||||
Get the name of the dictionaries for the end user. Use the base name of the
|
Get the name of the dictionaries for the end user. Use the base name of the
|
||||||
@@ -76,6 +81,7 @@ def get_dict_names(dict1_path, dict2_path):
|
|||||||
dict2_name = "dict2"
|
dict2_name = "dict2"
|
||||||
return dict1_name, dict2_name
|
return dict1_name, dict2_name
|
||||||
|
|
||||||
|
|
||||||
def compare_dicts(dict1, dict2, dict1_name, dict2_name):
|
def compare_dicts(dict1, dict2, dict1_name, dict2_name):
|
||||||
"""
|
"""
|
||||||
Compare the two dictionaries. Print out the result.
|
Compare the two dictionaries. Print out the result.
|
||||||
@@ -101,6 +107,7 @@ def compare_dicts(dict1, dict2, dict1_name, dict2_name):
|
|||||||
if not has_value_differences:
|
if not has_value_differences:
|
||||||
print " None"
|
print " None"
|
||||||
|
|
||||||
|
|
||||||
def print_key_diff(key_diff, dict1_name, dict2_name):
|
def print_key_diff(key_diff, dict1_name, dict2_name):
|
||||||
"""
|
"""
|
||||||
Prints the keys in the first dictionary and are in the second dictionary.
|
Prints the keys in the first dictionary and are in the second dictionary.
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ data_type_map = dict(
|
|||||||
longtext='text',
|
longtext='text',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def mysql(database_name, username, password):
|
def mysql(database_name, username, password):
|
||||||
p = subprocess.Popen(['mysql',
|
p = subprocess.Popen(['mysql',
|
||||||
'--user=%s' % username,
|
'--user=%s' % username,
|
||||||
@@ -61,8 +62,10 @@ def mysql(database_name, username, password):
|
|||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
sql_showtables, stderr = p.communicate()
|
sql_showtables, stderr = p.communicate()
|
||||||
tables = [re.sub('\|\s+([^\|*])\s+.*', '\1', x) for x in sql_showtables.split()[1:]]
|
tables = [re.sub(
|
||||||
connection_string = "legacy_db = DAL('mysql://%s:%s@localhost/%s')"%(username, password, database_name)
|
'\|\s+([^\|*])\s+.*', '\1', x) for x in sql_showtables.split()[1:]]
|
||||||
|
connection_string = "legacy_db = DAL('mysql://%s:%s@localhost/%s')" % (
|
||||||
|
username, password, database_name)
|
||||||
legacy_db_table_web2py_code = []
|
legacy_db_table_web2py_code = []
|
||||||
for table_name in tables:
|
for table_name in tables:
|
||||||
#get the sql create statement
|
#get the sql create statement
|
||||||
@@ -76,26 +79,30 @@ def mysql(database_name, username, password):
|
|||||||
if 'CREATE' in sql_create_stmnt: # check if the table exists
|
if 'CREATE' in sql_create_stmnt: # check if the table exists
|
||||||
#remove garbage lines from sql statement
|
#remove garbage lines from sql statement
|
||||||
sql_lines = sql_create_stmnt.split('\n')
|
sql_lines = sql_create_stmnt.split('\n')
|
||||||
sql_lines = [x for x in sql_lines if not(x.startswith('--') or x.startswith('/*') or x =='')]
|
sql_lines = [x for x in sql_lines if not(
|
||||||
|
x.startswith('--') or x.startswith('/*') or x == '')]
|
||||||
#generate the web2py code from the create statement
|
#generate the web2py code from the create statement
|
||||||
web2py_table_code = ''
|
web2py_table_code = ''
|
||||||
table_name = re.search('CREATE TABLE .(\S+). \(', sql_lines[0]).group(1)
|
table_name = re.search(
|
||||||
|
'CREATE TABLE .(\S+). \(', sql_lines[0]).group(1)
|
||||||
fields = []
|
fields = []
|
||||||
for line in sql_lines[1:-1]:
|
for line in sql_lines[1:-1]:
|
||||||
if re.search('KEY', line) or re.search('PRIMARY', line) or re.search(' ID', line) or line.startswith(')'):
|
if re.search('KEY', line) or re.search('PRIMARY', line) or re.search(' ID', line) or line.startswith(')'):
|
||||||
continue
|
continue
|
||||||
hit = re.search('(\S+)\s+(\S+)(,| )( .*)?', line)
|
hit = re.search('(\S+)\s+(\S+)(,| )( .*)?', line)
|
||||||
if hit!=None:
|
if hit is not None:
|
||||||
name, d_type = hit.group(1), hit.group(2)
|
name, d_type = hit.group(1), hit.group(2)
|
||||||
d_type = re.sub(r'(\w+)\(.*', r'\1', d_type)
|
d_type = re.sub(r'(\w+)\(.*', r'\1', d_type)
|
||||||
name = re.sub('`', '', name)
|
name = re.sub('`', '', name)
|
||||||
web2py_table_code += "\n Field('%s','%s'),"%(name,data_type_map[d_type])
|
web2py_table_code += "\n Field('%s','%s')," % (
|
||||||
|
name, data_type_map[d_type])
|
||||||
web2py_table_code = "legacy_db.define_table('%s',%s\n migrate=False)" % (table_name, web2py_table_code)
|
web2py_table_code = "legacy_db.define_table('%s',%s\n migrate=False)" % (table_name, web2py_table_code)
|
||||||
legacy_db_table_web2py_code.append(web2py_table_code)
|
legacy_db_table_web2py_code.append(web2py_table_code)
|
||||||
#----------------------------------------
|
#----------------------------------------
|
||||||
#write the legacy db to file
|
#write the legacy db to file
|
||||||
legacy_db_web2py_code = connection_string + "\n\n"
|
legacy_db_web2py_code = connection_string + "\n\n"
|
||||||
legacy_db_web2py_code += "\n\n#--------\n".join(legacy_db_table_web2py_code)
|
legacy_db_web2py_code += "\n\n#--------\n".join(
|
||||||
|
legacy_db_table_web2py_code)
|
||||||
return legacy_db_web2py_code
|
return legacy_db_web2py_code
|
||||||
|
|
||||||
regex = re.compile('(.*?):(.*?)@(.*)')
|
regex = re.compile('(.*?):(.*?)@(.*)')
|
||||||
@@ -104,4 +111,3 @@ if len(sys.argv)<2 or not regex.match(sys.argv[1]):
|
|||||||
else:
|
else:
|
||||||
m = regex.match(sys.argv[1])
|
m = regex.match(sys.argv[1])
|
||||||
print mysql(m.group(3), m.group(1), m.group(2))
|
print mysql(m.group(3), m.group(1), m.group(2))
|
||||||
|
|
||||||
|
|||||||
@@ -51,14 +51,16 @@ def query(conn, sql,*args):
|
|||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
ret = []
|
ret = []
|
||||||
try:
|
try:
|
||||||
if DEBUG: print >> sys.stderr, "QUERY: ", sql % args
|
if DEBUG:
|
||||||
|
print >> sys.stderr, "QUERY: ", sql % args
|
||||||
cur.execute(sql, args)
|
cur.execute(sql, args)
|
||||||
for row in cur:
|
for row in cur:
|
||||||
dic = {}
|
dic = {}
|
||||||
for i, value in enumerate(row):
|
for i, value in enumerate(row):
|
||||||
field = cur.description[i][0]
|
field = cur.description[i][0]
|
||||||
dic[field] = value
|
dic[field] = value
|
||||||
if DEBUG: print >> sys.stderr, "RET: ", dic
|
if DEBUG:
|
||||||
|
print >> sys.stderr, "RET: ", dic
|
||||||
ret.append(dic)
|
ret.append(dic)
|
||||||
return ret
|
return ret
|
||||||
finally:
|
finally:
|
||||||
@@ -75,7 +77,8 @@ def get_tables(conn, schema=SCHEMA):
|
|||||||
|
|
||||||
def get_fields(conn, table):
|
def get_fields(conn, table):
|
||||||
"Retrieve field list for a given table"
|
"Retrieve field list for a given table"
|
||||||
if DEBUG: print >> sys.stderr, "Processing TABLE", table
|
if DEBUG:
|
||||||
|
print >> sys.stderr, "Processing TABLE", table
|
||||||
rows = query(conn, """
|
rows = query(conn, """
|
||||||
SELECT column_name, data_type,
|
SELECT column_name, data_type,
|
||||||
is_nullable,
|
is_nullable,
|
||||||
@@ -142,7 +145,8 @@ def define_field(conn, table, field, pks):
|
|||||||
except (ValueError, SyntaxError):
|
except (ValueError, SyntaxError):
|
||||||
pass
|
pass
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise RuntimeError("Default unsupported '%s'" % field['column_default'])
|
raise RuntimeError(
|
||||||
|
"Default unsupported '%s'" % field['column_default'])
|
||||||
|
|
||||||
if not field['is_nullable']:
|
if not field['is_nullable']:
|
||||||
f['notnull'] = "True"
|
f['notnull'] = "True"
|
||||||
@@ -280,5 +284,3 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
# Start model code generation:
|
# Start model code generation:
|
||||||
define_db(cnn, db, host, port, user, passwd)
|
define_db(cnn, db, host, port, user, passwd)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -1,4 +1,6 @@
|
|||||||
import sys, glob
|
import sys
|
||||||
|
import glob
|
||||||
|
|
||||||
|
|
||||||
def read_fileb(filename, mode='rb'):
|
def read_fileb(filename, mode='rb'):
|
||||||
f = open(filename, mode)
|
f = open(filename, mode)
|
||||||
@@ -7,6 +9,7 @@ def read_fileb(filename, mode='rb'):
|
|||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def write_fileb(filename, value, mode='wb'):
|
def write_fileb(filename, value, mode='wb'):
|
||||||
f = open(filename, mode)
|
f = open(filename, mode)
|
||||||
try:
|
try:
|
||||||
@@ -18,7 +21,7 @@ for filename in glob.glob(sys.argv[1]):
|
|||||||
data1 = read_fileb(filename)
|
data1 = read_fileb(filename)
|
||||||
write_fileb(filename + '.bak2', data1)
|
write_fileb(filename + '.bak2', data1)
|
||||||
data2lines = read_fileb(filename).strip().split('\n')
|
data2lines = read_fileb(filename).strip().split('\n')
|
||||||
data2 = '\n'.join([line.rstrip().replace('\t',' '*2) for line in data2lines])+'\n'
|
data2 = '\n'.join([line.rstrip(
|
||||||
|
).replace('\t', ' ' * 2) for line in data2lines]) + '\n'
|
||||||
write_fileb(filename, data2)
|
write_fileb(filename, data2)
|
||||||
print filename, len(data1) - len(data2)
|
print filename, len(data1) - len(data2)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import sys
|
|||||||
import re
|
import re
|
||||||
from BeautifulSoup import BeautifulSoup as BS
|
from BeautifulSoup import BeautifulSoup as BS
|
||||||
|
|
||||||
|
|
||||||
def head(styles):
|
def head(styles):
|
||||||
title = '<title>{{=response.title or request.application}}</title>'
|
title = '<title>{{=response.title or request.application}}</title>'
|
||||||
items = '\n'.join(["{{response.files.append(URL(request.application,'static','%s'))}}" % (style) for style in styles])
|
items = '\n'.join(["{{response.files.append(URL(request.application,'static','%s'))}}" % (style) for style in styles])
|
||||||
@@ -41,9 +42,11 @@ div.error {
|
|||||||
</style>"""
|
</style>"""
|
||||||
return "\n%s\n%s\n{{include 'web2py_ajax.html'}}\n%s" % (title, items, loc)
|
return "\n%s\n%s\n{{include 'web2py_ajax.html'}}\n%s" % (title, items, loc)
|
||||||
|
|
||||||
|
|
||||||
def content():
|
def content():
|
||||||
return """<div class="flash">{{=response.flash or ''}}</div>{{include}}"""
|
return """<div class="flash">{{=response.flash or ''}}</div>{{include}}"""
|
||||||
|
|
||||||
|
|
||||||
def process(folder):
|
def process(folder):
|
||||||
indexfile = open(os.path.join(folder, 'index.html'), 'rb')
|
indexfile = open(os.path.join(folder, 'index.html'), 'rb')
|
||||||
try:
|
try:
|
||||||
@@ -53,8 +56,10 @@ def process(folder):
|
|||||||
styles = [x['href'] for x in soup.findAll('link')]
|
styles = [x['href'] for x in soup.findAll('link')]
|
||||||
soup.find('head').contents = BS(head(styles))
|
soup.find('head').contents = BS(head(styles))
|
||||||
try:
|
try:
|
||||||
soup.find('h1').contents=BS('{{=response.title or request.application}}')
|
soup.find(
|
||||||
soup.find('h2').contents=BS("{{=response.subtitle or '=response.subtitle'}}")
|
'h1').contents = BS('{{=response.title or request.application}}')
|
||||||
|
soup.find('h2').contents = BS(
|
||||||
|
"{{=response.subtitle or '=response.subtitle'}}")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
for match in (soup.find('div', id='menu'),
|
for match in (soup.find('div', id='menu'),
|
||||||
@@ -79,7 +84,7 @@ def process(folder):
|
|||||||
.sub("{{=response.flash or ''}}", page)
|
.sub("{{=response.flash or ''}}", page)
|
||||||
print page
|
print page
|
||||||
else:
|
else:
|
||||||
raise Exception, "Unable to convert"
|
raise Exception("Unable to convert")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
@@ -96,4 +101,3 @@ if __name__=='__main__':
|
|||||||
print 'Folder %s does not exist' % sys.argv[1]
|
print 'Folder %s does not exist' % sys.argv[1]
|
||||||
else:
|
else:
|
||||||
process(sys.argv[1])
|
process(sys.argv[1])
|
||||||
|
|
||||||
|
|||||||
+19
-10
@@ -38,7 +38,11 @@ gluon/contrib/pyrtf/
|
|||||||
gluon/contrib/pysimplesoap/
|
gluon/contrib/pysimplesoap/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os, shutil, glob
|
import sys
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import glob
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global REQUIRED, IGNORED
|
global REQUIRED, IGNORED
|
||||||
@@ -54,11 +58,10 @@ def main():
|
|||||||
REQUIRED = REQUIRED.replace('/', os.sep)
|
REQUIRED = REQUIRED.replace('/', os.sep)
|
||||||
IGNORED = IGNORED.replace('/', os.sep)
|
IGNORED = IGNORED.replace('/', os.sep)
|
||||||
|
|
||||||
|
|
||||||
# make a list of all files to include
|
# make a list of all files to include
|
||||||
files = [x.strip() for x in REQUIRED.split('\n') \
|
files = [x.strip() for x in REQUIRED.split('\n')
|
||||||
if x and not x[0] == '#']
|
if x and not x[0] == '#']
|
||||||
ignore = [x.strip() for x in IGNORED.split('\n') \
|
ignore = [x.strip() for x in IGNORED.split('\n')
|
||||||
if x and not x[0] == '#']
|
if x and not x[0] == '#']
|
||||||
|
|
||||||
def accept(filename):
|
def accept(filename):
|
||||||
@@ -69,20 +72,26 @@ def main():
|
|||||||
pattern = os.path.join('gluon', '*.py')
|
pattern = os.path.join('gluon', '*.py')
|
||||||
while True:
|
while True:
|
||||||
newfiles = [x for x in glob.glob(pattern) if accept(x)]
|
newfiles = [x for x in glob.glob(pattern) if accept(x)]
|
||||||
if not newfiles: break
|
if not newfiles:
|
||||||
|
break
|
||||||
files += newfiles
|
files += newfiles
|
||||||
pattern = os.path.join(pattern[:-3], '*.py')
|
pattern = os.path.join(pattern[:-3], '*.py')
|
||||||
# copy all files, make missing folder, build default.py
|
# copy all files, make missing folder, build default.py
|
||||||
files.sort()
|
files.sort()
|
||||||
defaultpy = os.path.join('applications','welcome','controllers','default.py')
|
defaultpy = os.path.join(
|
||||||
|
'applications', 'welcome', 'controllers', 'default.py')
|
||||||
for f in files:
|
for f in files:
|
||||||
dirs = f.split(os.path.sep)
|
dirs = f.split(os.path.sep)
|
||||||
for i in range(1, len(dirs)):
|
for i in range(1, len(dirs)):
|
||||||
try: os.mkdir(target+os.sep+os.path.join(*dirs[:i]))
|
try:
|
||||||
except OSError: pass
|
os.mkdir(target + os.sep + os.path.join(*dirs[:i]))
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
if f == defaultpy:
|
if f == defaultpy:
|
||||||
open(os.path.join(target,f),'w').write('def index(): return "hello"\n')
|
open(os.path.join(
|
||||||
|
target, f), 'w').write('def index(): return "hello"\n')
|
||||||
else:
|
else:
|
||||||
shutil.copyfile(f, os.path.join(target, f))
|
shutil.copyfile(f, os.path.join(target, f))
|
||||||
|
|
||||||
if __name__=='__main__': main()
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ def total_seconds(delta):
|
|||||||
Args:
|
Args:
|
||||||
delta: datetime.timedelta instance.
|
delta: datetime.timedelta instance.
|
||||||
"""
|
"""
|
||||||
return (delta.microseconds + (delta.seconds + (delta.days * 24 * 3600)) * \
|
return (delta.microseconds + (delta.seconds + (delta.days * 24 * 3600)) *
|
||||||
10 ** 6) / 10 ** 6
|
10 ** 6) / 10 ** 6
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ sys.path.insert(0, '.')
|
|||||||
file = sys.argv[1]
|
file = sys.argv[1]
|
||||||
apps = sys.argv[2:]
|
apps = sys.argv[2:]
|
||||||
|
|
||||||
|
|
||||||
def sync_language(d, data):
|
def sync_language(d, data):
|
||||||
''' this function makes sure a translated string will be prefered over an untranslated
|
''' this function makes sure a translated string will be prefered over an untranslated
|
||||||
string when syncing languages between apps. when both are translated, it prefers the
|
string when syncing languages between apps. when both are translated, it prefers the
|
||||||
@@ -68,4 +69,3 @@ for app in oapps:
|
|||||||
path2 = 'applications/%s/' % app
|
path2 = 'applications/%s/' % app
|
||||||
file2 = os.path.join(path2, 'languages', '%s.py' % file)
|
file2 = os.path.join(path2, 'languages', '%s.py' % file)
|
||||||
shutil.copyfile(file1, file2)
|
shutil.copyfile(file1, file2)
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ db_path = os.path.join(request.folder, 'databases')
|
|||||||
|
|
||||||
tk_db = DAL(db_string, folder=db_path, auto_import=True)
|
tk_db = DAL(db_string, folder=db_path, auto_import=True)
|
||||||
ts = TicketStorage(db=tk_db)
|
ts = TicketStorage(db=tk_db)
|
||||||
tk_table = ts._get_table(db=tk_db, tablename=ts.tablename, app=request.application)
|
tk_table = ts._get_table(
|
||||||
|
db=tk_db, tablename=ts.tablename, app=request.application)
|
||||||
|
|
||||||
|
|
||||||
hashes = {}
|
hashes = {}
|
||||||
@@ -48,4 +49,3 @@ while 1:
|
|||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
|
|
||||||
time.sleep(SLEEP_MINUTES * 60)
|
time.sleep(SLEEP_MINUTES * 60)
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ while 1:
|
|||||||
error = RestrictedError()
|
error = RestrictedError()
|
||||||
error.load(request, request.application, file)
|
error.load(request, request.application, file)
|
||||||
|
|
||||||
mail.send(to=administrator_email, subject='new web2py ticket', message=error.traceback)
|
mail.send(to=administrator_email,
|
||||||
|
subject='new web2py ticket', message=error.traceback)
|
||||||
|
|
||||||
os.unlink(os.path.join(path, file))
|
os.unlink(os.path.join(path, file))
|
||||||
time.sleep(SLEEP_MINUTES * 60)
|
time.sleep(SLEEP_MINUTES * 60)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import os
|
import os
|
||||||
import gzip
|
import gzip
|
||||||
|
|
||||||
|
|
||||||
def zip_static(filelist=[]):
|
def zip_static(filelist=[]):
|
||||||
tsave = 0
|
tsave = 0
|
||||||
for fi in filelist:
|
for fi in filelist:
|
||||||
@@ -24,7 +25,8 @@ def zip_static(filelist=[]):
|
|||||||
if zatime == atime and zmtime == mtime:
|
if zatime == atime and zmtime == mtime:
|
||||||
print 'skipping %s, already gzipped to the latest version' % os.path.basename(fi)
|
print 'skipping %s, already gzipped to the latest version' % os.path.basename(fi)
|
||||||
continue
|
continue
|
||||||
print 'gzipping %s to %s' % (os.path.basename(fi), os.path.basename(gfi))
|
print 'gzipping %s to %s' % (
|
||||||
|
os.path.basename(fi), os.path.basename(gfi))
|
||||||
f_in = open(fi, 'rb')
|
f_in = open(fi, 'rb')
|
||||||
f_out = gzip.open(gfi, 'wb')
|
f_out = gzip.open(gfi, 'wb')
|
||||||
f_out.writelines(f_in)
|
f_out.writelines(f_in)
|
||||||
|
|||||||
Reference in New Issue
Block a user