示例#1
0
def create_database(cfg, default_traits):
    dsn = cfg.get_dsn()
    dsn['dbname'] = 'mishmash'
    conn = QuickConn(dsn)
    cmd = StatementCursor(conn, 'create_database')
    for table in cmd.tables():
        cmd.execute('drop table %s' % table)
    start_schema(conn, default_traits)
    make_suites(conn)
    cmd.execute(grant_public(cmd.tables()))
    cmd.execute(grant_public(['current_environment'], 'ALL'))
def create_database(cfg, default_traits):
    dsn = cfg.get_dsn()
    dsn['dbname'] = 'mishmash'
    conn = QuickConn(dsn)
    cmd = StatementCursor(conn, 'create_database')
    for table in cmd.tables():
        cmd.execute('drop table %s' %table)
    start_schema(conn, default_traits)
    make_suites(conn)
    cmd.execute(grant_public(cmd.tables()))
    cmd.execute(grant_public(['current_environment'], 'ALL'))
示例#3
0
 def _connect(self, dbname):
     if self.connections.has_key(dbname):
         dialogs.Message("connection already exists for %s" % dbname)
     else:
         conn = BaseConnection(user=self._dbuser, host=self._dbhost, dbname=dbname, passwd=self._dbpasswd)
         self.connections[dbname] = conn
         cursor = StatementCursor(self.connections[dbname])
         rows = cursor.tables()
         tables = ScrollCList(rcmenu=self.table_edit_menu)
         tables.set_rows(rows, columns=["table"])
         self.append_page(tables, dbname)
         self.set_current_page(dbname)
示例#4
0
 def _connect(self, dbname):
     if self.connections.has_key(dbname):
         dialogs.Message('connection already exists for %s' % dbname)
     else:
         conn = BaseConnection(user=self._dbuser,
                               host=self._dbhost,
                               dbname=dbname,
                               passwd=self._dbpasswd)
         self.connections[dbname] = conn
         cursor = StatementCursor(self.connections[dbname])
         rows = cursor.tables()
         tables = ScrollCList(rcmenu=self.table_edit_menu)
         tables.set_rows(rows, columns=['table'])
         self.append_page(tables, dbname)
         self.set_current_page(dbname)
示例#5
0
class TableBrowser(CList):
    def __init__(self, conn):
        self.cmd = StatementCursor(conn, name='TableBrowser')
        CList.__init__(self, 'Tables', name='TableBrowser')
        self.set_rows(self.cmd.tables(), ['table'])
        self.set_row_select(self.__hello__)
        self.statement = Statement('select')
    def __hello__(self, listbox, row, column, event):
        self.statement.table = listbox.get_selected_data()[0]['table']
        table = self.statement.table
        tb = CList(table, name=table)
        rows = self.cmd.getall('*', table)
        cols = []
        if len(rows):
            cols = rows[0].keys()
        tb.set_rows(rows, cols)
        tb.set_usize(400,200)
示例#6
0
class PaellaProcessor(object):
    def __init__(self, conn):
        object.__init__(self)
        self.conn = conn
        self.__set_cursors__()
        self.main_path = None
        
    def parse_xml(self, filename):
        self.dbdata = PaellaParser(filename)
        self.main_path = dirname(filename)

    def start_schema(self):
        start_schema(self.conn)
        self._sync_suites()

    def _sync_suites(self):
        self.main.set_table('suites')
        current_suites = [row.suite for row in self.main.select()]
        for suite in self.dbdata.suites:
            if suite.name not in current_suites:
                self.main.insert(data=suite)
                make_suite(self.main, suite.name)
                insert_packages(self.main, suite.name)
            else:
                self.main.update(data=suite)

    def insert_profiles(self):
        path = join(self.main_path, 'profiles')
        print 'path is in insert_profiles', path
        xmlfiles = [join(path, x) for x in os.listdir(path) if x[-4:] == '.xml']
        profiles = PaellaProfiles(self.conn)
        for xmlfile in xmlfiles:
            xml = parse_file(xmlfile)
            elements = xml.getElementsByTagName('profile')
            if len(elements) != 1:
                raise Error, 'bad profile number %s' % len(elements)
            element = elements[0]
            parsed = ProfileParser(element)
            profiles.insert_profile(parsed)
        

    def insert_profile(self, profile):
        idata = {'profile' : profile.name,
                 'suite' : profile.suite}
        self.main.insert(table='profiles', data=idata)
        idata = {'profile' : profile.name,
                 'trait' : None,
                 'ord' : 0}
        for trait, ord in profile.traits:
            print trait, ord
            idata['trait'] = trait
            idata['ord'] = ord #str(ord)
            self.main.insert(table='profile_trait', data=idata)
        idata = {'profile' : profile.name,
                 'trait' : None,
                 'name' : None,
                 'value': None}
        for trait, name, value in profile.vars:
            idata['trait'] = trait
            idata['name'] = name
            idata['value'] = value
            self.main.insert(table='profile_variables', data=idata)
    

    def insert_traits(self, suite):
        self.__set_suite_cursors__(suite)
        traits = [trait for trait in self.dbdata.get_traits(suite)]
        self._insert_traits_(traits, suite)

    def _clear_traits(self, suite):
        self.__set_suite_cursors__(suite)
        self.traitparent.cmd.delete()
        self.traitpackage.cmd.delete()
        self.main.delete(table=ujoin(suite, 'variables'))
        self.traits.delete()

    def _insert_traits_(self, traits, suite):
        while len(traits):
            trait = traits[0]
            print 'inserting %s' %trait, len(traits)
            try:
                self._insert_trait_(trait, suite)
            except UnbornError:
                traits.append(trait)
            del traits[0]
            
    def _insert_trait_(self, trait, suite):
        traitdb = Trait(self.conn, suite)
        path = join(self.main_path, suite, trait + '.tar')
        traitdb.insert_trait(path, suite)
        
        
    def __set_cursors__(self):
        self.main = StatementCursor(self.conn, 'main_paella_cursor')
        self.all_traits = StatementCursor(self.conn, 'all_traits')
        self.all_traits.set_table('traits')

    def __set_suite_cursors__(self, suite):
        self.traits = StatementCursor(self.conn, 'traits')
        self.traits.set_table(ujoin(suite, 'traits'))
        self.traitparent = TraitParent(self.conn, suite)
        self.traitpackage = TraitPackage(self.conn, suite)
        self.traittemplate = TraitTemplate(self.conn, suite)
        self.traitdebconf = TraitDebconf(self.conn, suite)
        

    def create(self, filename):
        for table in self.main.tables():
            self.main.execute('drop table %s' %table)
        self.parse_xml(filename)
        self.start_schema()
        for suite in self.dbdata.suites:
            self.insert_traits(suite.name)
        self.insert_profiles()
示例#7
0
        self.setOrientation(QSplitter.Horizontal)
        self.listbox = QListView(self)
        #self.insertWidget(self.listbox)
        self.notebook = QTabBar(self)
        #self.addWidget(self.notebook)


cfg = PaellaConfig('database')
conn = PaellaConnection()
cursor = StatementCursor(conn)
app = QApplication(sys.argv)
#lv = QListView(None)
#lv.addColumn('section')
#for s in cursor.tables():
#    lv.insertItem(QListViewItem(lv, s))
#lv.show()
hello = QLabel('<font color=blue>%s <i>Qt!</i></font>' % str(cfg.section),
               None)
#lb = Listbox(None, cursor.select(table='gunny_templates'))
ln = ListNotebook()
ln.show()
ln.listbox.addColumn('table')
for t in cursor.tables():
    ln.listbox.insertItem(QListViewItem(ln.listbox, t))

app.setMainWidget(ln)

hello.show()
hello.setText(str(cfg.sections()))
app.exec_loop()
示例#8
0
class PaellaProcessor(object):
    def __init__(self, conn):
        object.__init__(self)
        self.conn = conn
        self.__set_cursors__()
        self.main_path = None

    def parse_xml(self, filename):
        self.dbdata = PaellaParser(filename)
        self.main_path = dirname(filename)

    def start_schema(self):
        start_schema(self.conn)
        self._sync_suites()

    def _sync_suites(self):
        self.main.set_table('suites')
        current_suites = [row.suite for row in self.main.select()]
        for suite in self.dbdata.suites:
            if suite.name not in current_suites:
                self.main.insert(data=suite)
                make_suite(self.main, suite.name)
                insert_packages(self.main, suite.name)
            else:
                self.main.update(data=suite)

    def insert_profiles(self):
        path = join(self.main_path, 'profiles')
        print 'path is in insert_profiles', path
        xmlfiles = [
            join(path, x) for x in os.listdir(path) if x[-4:] == '.xml'
        ]
        profiles = PaellaProfiles(self.conn)
        for xmlfile in xmlfiles:
            xml = parse_file(xmlfile)
            elements = xml.getElementsByTagName('profile')
            if len(elements) != 1:
                raise Error, 'bad profile number %s' % len(elements)
            element = elements[0]
            parsed = ProfileParser(element)
            profiles.insert_profile(parsed)

    def insert_profile(self, profile):
        idata = {'profile': profile.name, 'suite': profile.suite}
        self.main.insert(table='profiles', data=idata)
        idata = {'profile': profile.name, 'trait': None, 'ord': 0}
        for trait, ord in profile.traits:
            print trait, ord
            idata['trait'] = trait
            idata['ord'] = ord  #str(ord)
            self.main.insert(table='profile_trait', data=idata)
        idata = {
            'profile': profile.name,
            'trait': None,
            'name': None,
            'value': None
        }
        for trait, name, value in profile.vars:
            idata['trait'] = trait
            idata['name'] = name
            idata['value'] = value
            self.main.insert(table='profile_variables', data=idata)

    def insert_traits(self, suite):
        self.__set_suite_cursors__(suite)
        traits = [trait for trait in self.dbdata.get_traits(suite)]
        self._insert_traits_(traits, suite)

    def _clear_traits(self, suite):
        self.__set_suite_cursors__(suite)
        self.traitparent.cmd.delete()
        self.traitpackage.cmd.delete()
        self.main.delete(table=ujoin(suite, 'variables'))
        self.traits.delete()

    def _insert_traits_(self, traits, suite):
        while len(traits):
            trait = traits[0]
            print 'inserting %s' % trait, len(traits)
            try:
                self._insert_trait_(trait, suite)
            except UnbornError:
                traits.append(trait)
            del traits[0]

    def _insert_trait_(self, trait, suite):
        traitdb = Trait(self.conn, suite)
        path = join(self.main_path, suite, trait + '.tar')
        traitdb.insert_trait(path, suite)

    def __set_cursors__(self):
        self.main = StatementCursor(self.conn, 'main_paella_cursor')
        self.all_traits = StatementCursor(self.conn, 'all_traits')
        self.all_traits.set_table('traits')

    def __set_suite_cursors__(self, suite):
        self.traits = StatementCursor(self.conn, 'traits')
        self.traits.set_table(ujoin(suite, 'traits'))
        self.traitparent = TraitParent(self.conn, suite)
        self.traitpackage = TraitPackage(self.conn, suite)
        self.traittemplate = TraitTemplate(self.conn, suite)
        self.traitdebconf = TraitDebconf(self.conn, suite)

    def create(self, filename):
        for table in self.main.tables():
            self.main.execute('drop table %s' % table)
        self.parse_xml(filename)
        self.start_schema()
        for suite in self.dbdata.suites:
            self.insert_traits(suite.name)
        self.insert_profiles()
示例#9
0
        QSplitter.__init__(self, parent, 'hsplit')
        self.setOrientation(QSplitter.Horizontal)
        self.listbox = QListView(self)
        #self.insertWidget(self.listbox)
        self.notebook = QTabBar(self)
        #self.addWidget(self.notebook)
        

cfg = PaellaConfig('database')
conn = PaellaConnection()
cursor = StatementCursor(conn)
app = QApplication(sys.argv)
#lv = QListView(None)
#lv.addColumn('section')
#for s in cursor.tables():
#    lv.insertItem(QListViewItem(lv, s))
#lv.show()
hello = QLabel('<font color=blue>%s <i>Qt!</i></font>' % str(cfg.section), None)
#lb = Listbox(None, cursor.select(table='gunny_templates'))
ln = ListNotebook()
ln.show()
ln.listbox.addColumn('table')
for t in cursor.tables():
    ln.listbox.insertItem(QListViewItem(ln.listbox, t))

app.setMainWidget(ln)

hello.show()
hello.setText(str(cfg.sections()))
app.exec_loop()
示例#10
0
class RepositoryManager(object):
    def __init__(self, conn):
        self.conn = conn
        self.main = StatementCursor(self.conn, 'RepositoryMain')
        self.repos = StatementCursor(self.conn, 'Repository')
        self.repos.set_table('repository')
        self.sources = StatementCursor(self.conn, 'Sources')
        self.sources.set_table('sources')
        self.release = ReleaseCursor(self.conn)
        self.repsections = StatementCursor(self.conn, 'repos_section')
        self.repsections.set_table('repos_section')
        self.__init_db__()

    def __init_db__(self):
        if not len(self.main.tables()):
            map(self.main.create_table, primary_tables())

    def drop_source(self, name, type):
        nameclause = Eq('name', name)
        clause = nameclause & Eq('type', type)
        for section in self.get_sections(name):
            self.main.drop(list_tablename(name, type, section))
        self.sources.delete(clause=clause)
        sources = self.sources.select(clause=clause)
        if not len(sources):
            self.repsections.delete(clause=nameclause)
            self.repos.delete(clause=nameclause)

    def add_source(self, name, source):
        source = make_source(source)
        if name not in [x.name for x in self.repos.select()]:
            self.repos.insert(data=dict(name=name))
        clause = Eq('name', name) & Eq('type', source.type)
        count = int(
            self.sources.select(fields=['count(name)'], clause=clause)[0][0])
        if count == 0:
            if islocaluri(source.uri):
                data = dict(name=name,
                            type=source.type,
                            uri=source.uri,
                            suite=source.suite)
                self.sources.insert(data=data)
                current_sections = self.get_sections(name)
                sdata = dict(name=name, section=None)
                for section in source.sections:
                    if section not in current_sections:
                        sdata['section'] = section
                        self.repsections.insert(data=sdata)
                    fullparse = FullParseTable(name, source.type, section)
                    if fullparse.name not in self.main.tables():
                        self.main.create_table(fullparse)
                    listtable = ListTable(name, source.type, section)
                    if listtable.name not in self.main.tables():
                        self.main.create_table(listtable)
            else:
                raise Error, 'local uris first'
        else:
            if not islocaluri(source.uri):
                data = dict(remote=source.uri)
                self.sources.update(data=data, clause=clause)
            else:
                raise ExistsError, 'already there'

    def get_sections(self, name):
        clause = Eq('name', name)
        return [
            x.section for x in self.repsections.iselect(fields=['section'],
                                                        clause=clause)
        ]

    def make_source_line(self, name, type, remote=False):
        repsrc = self.make_source(name, type, remote)
        return str(repsrc)

    def make_source(self, name, type, remote=False):
        clause = Eq('name', name) & Eq('type', type)
        source = self.sources.select_row(clause=clause)
        repsrc = RepositorySource()
        repsrc.type = source.type
        if remote:
            repsrc.uri = source.remote
        else:
            repsrc.uri = source.uri
        repsrc.suite = source.suite
        repsrc.sections = self.get_sections(name)
        repsrc.set_path()
        return repsrc

    def listfile(self, name, type, section=None):
        source = self.make_source(name, type)
        release = Release(source)
        print 'Need to pull from database!!!'
        if source.has_release():
            return join(source.distpath, release.path(section))
        else:
            return join(source.distpath, source.listfile())

    def get_remote(self, name, type, remote=True):
        return self.make_source(name, type, remote=True)

    def parse_section(self, name, type, section=None):
        listfile = self.listfile(name, type, section)
        debug(listfile)
        if not isfile(listfile):
            raise NoFileError, 'file not there'
        if type == 'deb':
            return full_parse(listfile)
        elif type == 'deb-src':
            return parse_sources(listfile)
        else:
            raise Error, 'bad source type'

    def add_repository(self, name):
        self.repos.insert(data=dict(name=name))
示例#11
0
class RepositoryManager(object):
    def __init__(self, conn):
        self.conn = conn
        self.main = StatementCursor(self.conn, 'RepositoryMain')
        self.repos = StatementCursor(self.conn, 'Repository')
        self.repos.set_table('repository')
        self.sources = StatementCursor(self.conn, 'Sources')
        self.sources.set_table('sources')
        self.release = ReleaseCursor(self.conn)
        self.repsections = StatementCursor(self.conn, 'repos_section')
        self.repsections.set_table('repos_section')
        self.__init_db__()
        
    def __init_db__(self):
        if not len(self.main.tables()):
            map(self.main.create_table, primary_tables())

    def drop_source(self, name, type):
        nameclause = Eq('name', name)
        clause = nameclause & Eq('type', type)
        for section in self.get_sections(name):
            self.main.drop(list_tablename(name, type, section))
        self.sources.delete(clause=clause)
        sources = self.sources.select(clause=clause)
        if not len(sources):
            self.repsections.delete(clause=nameclause)
            self.repos.delete(clause=nameclause)
            
    def add_source(self, name, source):
        source = make_source(source)
        if name not in [x.name for x in self.repos.select()]:
            self.repos.insert(data=dict(name=name))
        clause = Eq('name', name) & Eq('type', source.type)
        count = int(self.sources.select(fields=['count(name)'], clause=clause)[0][0])
        if count == 0:
            if islocaluri(source.uri):
                data = dict(name=name, type=source.type, uri=source.uri,
                            suite=source.suite)
                self.sources.insert(data=data)
                current_sections = self.get_sections(name)
                sdata = dict(name=name, section=None)
                for section in source.sections:
                    if section not in current_sections:
                        sdata['section'] = section
                        self.repsections.insert(data=sdata)
                    fullparse = FullParseTable(name, source.type, section)
                    if fullparse.name not in self.main.tables():
                        self.main.create_table(fullparse)
                    listtable = ListTable(name, source.type, section)
                    if listtable.name not in self.main.tables():
                        self.main.create_table(listtable)
            else:
                raise Error, 'local uris first'
        else:
            if not islocaluri(source.uri):
                data = dict(remote=source.uri)
                self.sources.update(data=data, clause=clause)
            else:
                raise ExistsError, 'already there'

    def get_sections(self, name):
        clause = Eq('name', name)
        return [x.section for x in self.repsections.iselect(fields=['section'], clause=clause)]

    def make_source_line(self, name, type, remote=False):
        repsrc = self.make_source(name, type, remote)
        return str(repsrc)

    def make_source(self, name, type, remote=False):
        clause = Eq('name', name) & Eq('type', type)
        source = self.sources.select_row(clause=clause)
        repsrc = RepositorySource()
        repsrc.type = source.type
        if remote:
            repsrc.uri = source.remote
        else:
            repsrc.uri = source.uri
        repsrc.suite = source.suite
        repsrc.sections = self.get_sections(name)
        repsrc.set_path()
        return repsrc

    def listfile(self, name, type, section=None):
        source = self.make_source(name, type)
        release = Release(source)
        print 'Need to pull from database!!!'
        if source.has_release():
            return join(source.distpath, release.path(section))
        else:
            return join(source.distpath, source.listfile())
    def get_remote(self, name, type, remote=True):
        return self.make_source(name, type, remote=True)

    def parse_section(self, name, type, section=None):
        listfile = self.listfile(name, type, section)
        debug(listfile)
        if not isfile(listfile):
            raise NoFileError, 'file not there'
        if type == 'deb':
            return full_parse(listfile)
        elif type == 'deb-src':
            return parse_sources(listfile)
        else:
            raise Error, 'bad source type'

    def add_repository(self, name):
        self.repos.insert(data=dict(name=name))