cpdb.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:StuffShare 作者: StuffShare 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号