def execute(self, cmd):
try:
if not '-table ' in cmd:
exec cmd
else:
file = None
table = None
fields = []
items = cmd.split()
invalidParams = []
table = self.getTable(items[1])
allowedParams = ['fields', 'file']
for i in items:
if '=' in i and not i.split('=')[0] in allowedParams:
try:
invalidParams.append(i)
except Exception, err:
raise Exception('invalid parameter\n%s' % i)
else:
if 'file=' in i:
file = os.path.abspath(i.split('=')[0].strip())
if 'fields=' in i:
for field in i.split('=')[1].split():
if field in self.db[table].fields:
fields.append(field.strip())
if len(invalidParams) > 0:
print('the following parameter(s) is not valid\n%s' %
','.join(invalidParams))
else:
try:
self.cmd_table(table, file, fields)
except Exception, err:
print('could not generate table for table %s\n%s' % (table, err))
except Exception, err:
print('sorry, can not do that!\n%s' % err)
评论列表
文章目录