コード例 #1
0
ファイル: main.py プロジェクト: BackupTheBerlios/paella-svn
class PaellaDatabaseElement(Element):
    def __init__(self):
        Element.__init__(self, 'paelladatabase')
        self.aptsources = AptSourceListElement()
        self.appendChild(self.aptsources)
        self.suites_element = SuitesElement()
        self.suites = {}
        self.suite_traits = {}
        self.appendChild(self.suites_element)
        
    def append_apt_source(self, apt_id, uri, dist, sections, local_path):
        element = AptSourceElement(apt_id, uri, dist, sections, local_path)
        self.aptsources.appendChild(element)
        
    def append_suite(self, suite):
        element = SuiteElement(suite)
        self.suites[suite] = element
        self.suites_element.appendChild(element)

    def append_suite_apt_source(self, suite, apt_id, order):
        element = SuiteAptElement(suite, apt_id, order)
        self.suites[suite].appendChild(element)

    def append_suite_traits(self, suite, traits=[]):
        element = TraitsElement(suite)
        self.suite_traits[suite] = element
        for trait in traits:
            self.append_trait(suite, trait)
        self.appendChild(element)

    def append_trait(self, suite, trait):
        self.suite_traits[suite].append_trait(trait)
コード例 #2
0
ファイル: main.py プロジェクト: pombredanne/paella-svn
class PaellaDatabaseElement(Element):
    def __init__(self):
        Element.__init__(self, 'paelladatabase')
        self.aptsources = AptSourceListElement()
        self.appendChild(self.aptsources)
        self.suites_element = SuitesElement()
        self.suites = {}
        self.suite_traits = {}
        self.appendChild(self.suites_element)

    def append_apt_source(self, apt_id, uri, dist, sections, local_path):
        element = AptSourceElement(apt_id, uri, dist, sections, local_path)
        self.aptsources.appendChild(element)

    def append_suite(self, suite):
        element = SuiteElement(suite)
        self.suites[suite] = element
        self.suites_element.appendChild(element)

    def append_suite_apt_source(self, suite, apt_id, order):
        element = SuiteAptElement(suite, apt_id, order)
        self.suites[suite].appendChild(element)

    def append_suite_traits(self, suite, traits=[]):
        element = TraitsElement(suite)
        self.suite_traits[suite] = element
        for trait in traits:
            self.append_trait(suite, trait)
        self.appendChild(element)

    def append_trait(self, suite, trait):
        self.suite_traits[suite].append_trait(trait)
コード例 #3
0
ファイル: main.py プロジェクト: pombredanne/paella-svn
 def __init__(self):
     Element.__init__(self, 'paelladatabase')
     self.aptsources = AptSourceListElement()
     self.appendChild(self.aptsources)
     self.suites_element = SuitesElement()
     self.suites = {}
     self.suite_traits = {}
     self.appendChild(self.suites_element)
コード例 #4
0
ファイル: main.py プロジェクト: BackupTheBerlios/paella-svn
 def __init__(self, conn, path='/'):
     Element.__init__(self, 'paelladatabase')
     self.conn = conn
     self.stmt = StatementCursor(self.conn)
     self._profile_traits_ = ProfileTrait(self.conn)
     self.path = path
     self.aptsources = AptSourceListElement()
     self.appendChild(self.aptsources)
     if 'apt_sources' in self.stmt.tables():
         for row in self.stmt.select(table='apt_sources', order=['apt_id']):
             element = AptSourceElement(row.apt_id, row.uri, row.dist, row.sections,
                                        row.local_path)
             self.aptsources.appendChild(element)
         self.suites = SuitesElement()
         self.appendChild(self.suites)
         for row in self._suite_rows():
             args = map(str, [row.suite, row.nonus, row.updates, row.local, row.common])
             element = SuiteElement(*args)
             for suiteapt in self.stmt.select(table='suite_apt_sources', order=['ord'],
                                              clause=Eq('suite', row.suite)):
                 element.appendChild(SuiteAptElement(row.suite,
                                                     suiteapt.apt_id, str(suiteapt.ord)))
             self.suites.appendChild(element)
     else:
         print 'WARNING, apt_sources table does not exist, backing up anyway'
     self.profiles = PaellaProfiles(self.conn)
     self.family = Family(self.conn)
     suites = [x.suite for x in self._suite_rows()]
     for suite in suites:
         self.appendChild(TraitsElement(self.conn, suite))
コード例 #5
0
ファイル: main.py プロジェクト: BackupTheBerlios/paella-svn
 def __init__(self):
     Element.__init__(self, 'paelladatabase')
     self.aptsources = AptSourceListElement()
     self.appendChild(self.aptsources)
     self.suites_element = SuitesElement()
     self.suites = {}
     self.suite_traits = {}
     self.appendChild(self.suites_element)
コード例 #6
0
ファイル: main.py プロジェクト: BackupTheBerlios/paella-svn
class PaellaDatabase(Element):
    def __init__(self, conn, path='/'):
        Element.__init__(self, 'paelladatabase')
        self.conn = conn
        self.stmt = StatementCursor(self.conn)
        self._profile_traits_ = ProfileTrait(self.conn)
        self.path = path
        self.aptsources = AptSourceListElement()
        self.appendChild(self.aptsources)
        if 'apt_sources' in self.stmt.tables():
            for row in self.stmt.select(table='apt_sources', order=['apt_id']):
                element = AptSourceElement(row.apt_id, row.uri, row.dist, row.sections,
                                           row.local_path)
                self.aptsources.appendChild(element)
            self.suites = SuitesElement()
            self.appendChild(self.suites)
            for row in self._suite_rows():
                args = map(str, [row.suite, row.nonus, row.updates, row.local, row.common])
                element = SuiteElement(*args)
                for suiteapt in self.stmt.select(table='suite_apt_sources', order=['ord'],
                                                 clause=Eq('suite', row.suite)):
                    element.appendChild(SuiteAptElement(row.suite,
                                                        suiteapt.apt_id, str(suiteapt.ord)))
                self.suites.appendChild(element)
        else:
            print 'WARNING, apt_sources table does not exist, backing up anyway'
        self.profiles = PaellaProfiles(self.conn)
        self.family = Family(self.conn)
        suites = [x.suite for x in self._suite_rows()]
        for suite in suites:
            self.appendChild(TraitsElement(self.conn, suite))

    def _suite_rows(self):
        return self.stmt.select(table='suites', order='suite')

    def write(self, filename):
        path = join(self.path, filename)
        xmlfile = file(path, 'w')
        self.writexml(xmlfile, indent='\t', newl='\n', addindent='\t')

    def backup(self, path=None):
        if path is None:
            path = self.path
        if not isdir(path):
            raise Error, '%s not a directory' % path
        dbfile = file(join(path, 'database.xml'), 'w')
        self.writexml(dbfile, indent='\t', newl='\n', addindent='\t')
        dbfile.close()
        self.backup_profiles(path)
        self.backup_families(path)
        suites = [x.suite for x in self._suite_rows()]
        for suite in suites:
            makepaths(join(path, suite))
            trait = Trait(self.conn, suite)
            for t in trait.get_trait_list():
                trait.set_trait(t)
                trait.export_trait(join(path, suite))

    def backup_profiles(self, path=None):
        profiles_dir = join(path, 'profiles')
        makepaths(profiles_dir)
        self.profiles.export_profiles(profiles_dir)

    def backup_families(self, path=None):
        fpath = join(path, 'families')
        makepaths(fpath)
        self.family.export_families(fpath)