コード例 #1
0
ファイル: admin.py プロジェクト: pombredanne/paella-svn
 def __init__(self, cfg, dbname):
     object.__init__(self)
     self.conn = QuickConn(cfg)
     self.cursor = StatementCursor(self.conn, name='AdminConnection')
     self.stmt = Statement('select')
     self.dbname = dbname
     self.set_path(cfg.get('database', 'export_path'))
コード例 #2
0
ファイル: admin.py プロジェクト: BackupTheBerlios/paella-svn
 def __init__(self, cfg, dbname):
     object.__init__(self)
     self.conn = QuickConn(cfg)
     self.cursor = StatementCursor(self.conn, name='AdminConnection')
     self.stmt = Statement('select')
     self.dbname = dbname
     self.set_path(cfg.get('database', 'export_path'))
コード例 #3
0
class XmlDatabase(object):
    def __init__(self, conn, path):
        object.__init__(self)
        self.conn = conn
        self.path = path
        self.cursor = StatementCursor(self.conn, name='XmlDatabase')
        self.element = Element('Database')

    def table(self, name, key=None):
        rows = self.cursor.select(table=name, order=key)
        return TableElement(name, rows, key)

    def tables(self):
        element = Element('tables')
        for table in self.cursor.tables():
            element.appendChild(self.table(table))
        return element
コード例 #4
0
ファイル: xmlgen.py プロジェクト: BackupTheBerlios/paella-svn
class XmlDatabase(object):
    def __init__(self, conn, path):
        object.__init__(self)
        self.conn = conn
        self.path = path
        self.cursor = StatementCursor(self.conn, name='XmlDatabase')
        self.element = Element('Database')

    def table(self, name, key=None):
        rows = self.cursor.select(table=name, order=key)
        return TableElement(name, rows, key)

    def tables(self):
        element = Element('tables')
        for table in self.cursor.tables():
            element.appendChild(self.table(table))
        return element
コード例 #5
0
ファイル: admin.py プロジェクト: BackupTheBerlios/useless-svn
 def __init__(self, user=None, host=None, dbname=None, passwd=None,
              port=5432):
     object.__init__(self)
     self.conn = BasicConnection(user=user, host=host, dbname=dbname,
                                 passwd=passwd, port=port)
     self.cursor = StatementCursor(self.conn, name='AdminConnection')
     self.stmt = Statement('select')
     self.dbname = dbname
     self.set_path(cfg.get('database', 'export_path'))
コード例 #6
0
 def create_table(self, table):
     if table.name[:7] != "lp_log_":
         StatementCursor.create_table(self, table)
         logtable = LogTable(table)
         StatementCursor.create_table(self, logtable)
         self.create_trigger(ActionTrigger(table.name))
コード例 #7
0
 def __init__(self, conn, name=None):
     StatementCursor.__init__(self, conn, name=name)
コード例 #8
0
ファイル: highlevel.py プロジェクト: pombredanne/paella-svn
 def create_table(self, table):
     if table.name[:7] != 'lp_log_':
         StatementCursor.create_table(self, table)
         logtable = LogTable(table)
         StatementCursor.create_table(self, logtable)
         self.create_trigger(ActionTrigger(table.name))
コード例 #9
0
ファイル: highlevel.py プロジェクト: pombredanne/paella-svn
 def __init__(self, conn, name=None):
     StatementCursor.__init__(self, conn, name=name)
コード例 #10
0
ファイル: admin.py プロジェクト: pombredanne/paella-svn
class AdminConnection(object):
    def __init__(self, cfg, dbname):
        object.__init__(self)
        self.conn = QuickConn(cfg)
        self.cursor = StatementCursor(self.conn, name='AdminConnection')
        self.stmt = Statement('select')
        self.dbname = dbname
        self.set_path(cfg.get('database', 'export_path'))

    def set_path(self, directory):
        self.path = directory
        makepaths(self.path)
        os.system('chmod 777 %s' % self.path)

    def to_tsv(self, table, key=None):
        self.stmt.table = table
        query = self.stmt.select(order=key)
        tsv = file(join(self.path, table + '.tsv'), 'w')
        self.cursor.execute(query)
        fields = [x[0] for x in self.cursor.description]
        tsv.write('\t'.join(map(quote, fields)) + '\n')
        row = self.cursor.fetchone()
        while row:
            line = []
            for field in row:
                if field == None:
                    field = 'NULL'
                else:
                    field = str(field)
                line.append(quote(field))
            tsv.write('\t'.join(line) + '\n')
            row = self.cursor.fetchone()
        tsv.close()

    def set_table(self, table):
        self.stmt.set_table(table)

    def insert(self, table):
        self.cursor.set_table(table)
        tsv = Parser(join(self.path, table + '.tsv'))
        for row in tsv:
            self.cursor.insert(data=row)

    def copyto(self, table):
        path = join(self.path, table + '.bkup')
        self.cursor.copyto(table, path)

    def copyfrom(self, table):
        path = join(self.path, table + '.bkup')
        self.cursor.copyfrom(table, path)

    def backup(self):
        map(self.copyto, self.cursor.tables())
コード例 #11
0
ファイル: admin.py プロジェクト: BackupTheBerlios/paella-svn
class AdminConnection(object):
    def __init__(self, cfg, dbname):
        object.__init__(self)
        self.conn = QuickConn(cfg)
        self.cursor = StatementCursor(self.conn, name='AdminConnection')
        self.stmt = Statement('select')
        self.dbname = dbname
        self.set_path(cfg.get('database', 'export_path'))

    def set_path(self, directory):
        self.path = directory
        makepaths(self.path)
        os.system('chmod 777 %s' % self.path)
        
    def to_tsv(self, table, key=None):
        self.stmt.table = table
        query = self.stmt.select(order=key)
        tsv = file(join(self.path, table + '.tsv'), 'w')
        self.cursor.execute(query)
        fields = [x[0] for x in self.cursor.description]
        tsv.write('\t'.join(map(quote, fields))+'\n')
        row = self.cursor.fetchone()
        while row:
            line = []
            for field in row:
                if field == None:
                    field = 'NULL'
                else:
                    field = str(field)
                line.append(quote(field))
            tsv.write('\t'.join(line)+'\n')
            row = self.cursor.fetchone()
        tsv.close()
        
    def set_table(self, table):
        self.stmt.set_table(table)

    def insert(self, table):
        self.cursor.set_table(table)
        tsv = Parser(join(self.path, table + '.tsv'))
        for row in tsv:
            self.cursor.insert(data=row)

    def copyto(self, table):
        path = join(self.path, table + '.bkup')
        self.cursor.copyto(table, path)

    def copyfrom(self, table):
        path = join(self.path, table + '.bkup')
        self.cursor.copyfrom(table, path)


    def backup(self):
        map(self.copyto, self.cursor.tables())
コード例 #12
0
ファイル: admin.py プロジェクト: BackupTheBerlios/useless-svn
class AdminConnection(object):
    """This isn't being used anymore.  It's been updated to use
    the BasicConnection class, but it's probably going to be
    transferred to another object one day, or removed
    completely."""
    def __init__(self, user=None, host=None, dbname=None, passwd=None,
                 port=5432):
        object.__init__(self)
        self.conn = BasicConnection(user=user, host=host, dbname=dbname,
                                    passwd=passwd, port=port)
        self.cursor = StatementCursor(self.conn, name='AdminConnection')
        self.stmt = Statement('select')
        self.dbname = dbname
        self.set_path(cfg.get('database', 'export_path'))

    def set_path(self, directory):
        self.path = directory
        makepaths(self.path)
        os.system('chmod 777 %s' % self.path)
        
    def to_tsv(self, table, key=None):
        self.stmt.table = table
        query = self.stmt.select(order=key)
        tsv = file(join(self.path, table + '.tsv'), 'w')
        self.cursor.execute(query)
        fields = [x[0] for x in self.cursor.description]
        tsv.write('\t'.join(map(quote, fields))+'\n')
        row = self.cursor.fetchone()
        while row:
            line = []
            for field in row:
                if field == None:
                    field = 'NULL'
                else:
                    field = str(field)
                line.append(quote(field))
            tsv.write('\t'.join(line)+'\n')
            row = self.cursor.fetchone()
        tsv.close()
        
    def set_table(self, table):
        self.stmt.set_table(table)

    def insert(self, table):
        self.cursor.set_table(table)
        tsv = Parser(join(self.path, table + '.tsv'))
        for row in tsv:
            self.cursor.insert(data=row)

    def copyto(self, table):
        path = join(self.path, table + '.bkup')
        self.cursor.copyto(table, path)

    def copyfrom(self, table):
        path = join(self.path, table + '.bkup')
        self.cursor.copyfrom(table, path)


    def backup(self):
        map(self.copyto, self.cursor.tables())
コード例 #13
0
 def __init__(self, conn, path):
     object.__init__(self)
     self.conn = conn
     self.path = path
     self.cursor = StatementCursor(self.conn, name='XmlDatabase')
     self.element = Element('Database')
コード例 #14
0
def backup_database(conn, path):
    element = Element('xml_database')
    cursor = StatementCursor(conn, 'backup_database')
コード例 #15
0
#generate xml
class XmlDatabase(object):
    def __init__(self, conn, path):
        object.__init__(self)
        self.conn = conn
        self.path = path
        self.cursor = StatementCursor(self.conn, name='XmlDatabase')
        self.element = Element('Database')

    def table(self, name, key=None):
        rows = self.cursor.select(table=name, order=key)
        return TableElement(name, rows, key)

    def tables(self):
        element = Element('tables')
        for table in self.cursor.tables():
            element.appendChild(self.table(table))
        return element


def backup_database(conn, path):
    element = Element('xml_database')
    cursor = StatementCursor(conn, 'backup_database')


if __name__ == '__main__':
    from paella.db.lowlevel import LocalConnection
    conn = LocalConnection('repos_db')
    s = StatementCursor(conn)
コード例 #16
0
ファイル: xmlgen.py プロジェクト: BackupTheBerlios/paella-svn
 def __init__(self, conn, path):
     object.__init__(self)
     self.conn = conn
     self.path = path
     self.cursor = StatementCursor(self.conn, name='XmlDatabase')
     self.element = Element('Database')