Beispiel #1
0
 def __init__(self, conn_info):
     super(Generator, self).__init__()
     conn_info = conn_info.split('|')
     self.db2 = DB2(*conn_info)
     self.meta = Metadata(self.db2)
     self.copier = DataCopier(self.db2, self.meta)
     self.tables = self.meta.tables()
Beispiel #2
0
class Generator(cmd.Cmd, object):
    
    intro = 'Type ?command to see help for that command.'
    
    
    def __init__(self, conn_info):
        super(Generator, self).__init__()
        conn_info = conn_info.split('|')
        self.db2 = DB2(*conn_info)
        self.meta = Metadata(self.db2)
        self.copier = DataCopier(self.db2, self.meta)
        self.tables = self.meta.tables()
    
    def complete_copy(self, text, state, begidx, endidx):            
        if text:
            text = text.upper()
            response = [s 
                        for s in self.tables
                        if s and s.startswith(text)]
        else:
            response = self.tables[:]
        return response
    
    def help_copy(self):
        print '\n'.join([ 'Generate a new row for table, using existing records as sample data.',
                           '\tformat: copy [table name]',
                           'arguments: ',
                           '\ttable name: schema.table'])    
    
    def do_copy(self, table):
        if table:
            self.copier.copy(table)
        else:
            print 'table name must be specified'
            
    def help_modification(self):
        print '\n'.join(['Display previously added records.',
                         '\tformat: index (schema, table, record)'])
    
    def do_modification(self, s):
        for idx, item in enumerate(self.copier.get_modifications()):
            print idx, item
            
    def do_undo(self, modi_idx):
        self.copier.undo(modi_idx)
    
    def do_EOF(self, line):
        return True 
    
    
    def close(self):
        self.db2.disconnect()

    def onecmd(self, cmd):
        try:
            return super(Generator, self).onecmd(cmd)
        except Exception:
            tb_to_stdout()