本文整理汇总了Python中family.Family.export_families方法的典型用法代码示例。如果您正苦于以下问题:Python Family.export_families方法的具体用法?Python Family.export_families怎么用?Python Family.export_families使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类family.Family
的用法示例。
在下文中一共展示了Family.export_families方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PaellaDatabase
# 需要导入模块: from family import Family [as 别名]
# 或者: from family.Family import export_families [as 别名]
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.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)
self.suites.appendChild(element)
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.backup_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)
示例2: PaellaExporter
# 需要导入模块: from family import Family [as 别名]
# 或者: from family.Family import export_families [as 别名]
class PaellaExporter(object):
def __init__(self, conn):
self.conn = conn
self.cursor = self.conn.cursor(statement=True)
self.suitecursor = SuiteCursor(self.conn)
self.init_db_element()
if len(self.cursor.tables()):
self.setup_cursors()
def setup_cursors(self):
self.profile = Profile(self.conn)
self.family = Family(self.conn)
self.machines = MachineHandler(self.conn)
self.diskconfig = DiskConfigHandler(self.conn)
def init_db_element(self):
self.dbelement = PaellaDatabaseElement()
def make_complete_db_element(self):
self.init_db_element()
self._append_apt_sources_to_db_element()
fields = ['suite']
for suite in self.suitecursor.get_suites():
self._append_suite_to_db_element(suite)
def _append_apt_sources_to_db_element(self):
rows = self.cursor.select(table='apt_sources', order=['apt_id'])
for row in rows:
self.dbelement.append_apt_source(row.apt_id, row.uri, row.dist,
row.sections, row.local_path)
def _append_suite_to_db_element(self, suite):
self.dbelement.append_suite(suite)
rows = self.cursor.select(table='suite_apt_sources', order=['ord'],
clause=Eq('suite', suite))
for row in rows:
self.dbelement.append_suite_apt_source(row.suite, row.apt_id,
str(row.ord))
rows = self.cursor.select(fields=['trait'], table='%s_traits' % suite,
order=['trait'])
traits = [row.trait for row in rows]
self.dbelement.append_suite_traits(suite, traits=traits)
def set_db_export_path(self, dirname):
self.db_export_path = path(dirname)
def export_db_element(self, dirname=None, filename='database.xml'):
if dirname is None:
dirname = self.db_export_path
filename = path(dirname) / filename
dbfile = filename.open('w')
self.dbelement.writexml(dbfile, indent='\t', newl='\n', addindent='\t')
dbfile.close()
def _make_suite_export_path(self, suite):
suitedir = self.db_export_path / suite
makepaths(suitedir)
return suitedir
def export_all_profiles(self, dirname=None):
if dirname is None:
dirname = self.db_export_path / 'profiles'
makepaths(dirname)
profiles = self.profile.get_profile_list()
self.report_total_profiles(len(profiles))
env = self.profile.make_environment_object()
for profile in profiles:
env.set_profile(profile)
self.profile.export_profile(dirname, profile=profile, env=env)
self.report_profile_exported(profile)
def export_all_diskconfigs(self, dirname=None):
if dirname is None:
dirname = self.db_export_path / 'diskconfig'
makepaths(dirname)
for row in self.diskconfig.cursor.select():
filename = row.name
diskconfig = dirname / filename
diskconfig.write_text(row.content)
def export_all_families(self, dirname=None):
if dirname is None:
dirname = self.db_export_path / 'families'
makepaths(dirname)
self.family.export_families(dirname)
def export_trait(self, trait, suite=None, dirname=None, traitdb=None):
if traitdb is None:
if suite is None:
RuntimeError , "you must pass a suite if you don't pass a Trait object"
print "make new traitdb"
traitdb = Trait(self.conn, suite)
traitdb.set_trait(trait)
if suite is None:
suite = traitdb.suite
if dirname is None:
dirname = self._make_suite_export_path(suite)
#.........这里部分代码省略.........
示例3: PaellaDatabase
# 需要导入模块: from family import Family [as 别名]
# 或者: from family.Family import export_families [as 别名]
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)