當前位置: 首頁>>代碼示例>>Python>>正文


Python Family.import_family_xml方法代碼示例

本文整理匯總了Python中family.Family.import_family_xml方法的典型用法代碼示例。如果您正苦於以下問題:Python Family.import_family_xml方法的具體用法?Python Family.import_family_xml怎麽用?Python Family.import_family_xml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在family.Family的用法示例。


在下文中一共展示了Family.import_family_xml方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: PaellaImporter

# 需要導入模塊: from family import Family [as 別名]
# 或者: from family.Family import import_family_xml [as 別名]
class PaellaImporter(object):
    def __init__(self, conn):
        self.conn = conn
        self.suitecursor = SuiteCursor(self.conn)
        self.aptsrc = AptSourceHandler(self.conn)
        self.main_path = None
        self.profile = Profile(self.conn)
        self.family = Family(self.conn)
        
    def set_main_path(self, dirname):
        self.main_path = path(dirname)
        
    def parse_main_xml(self, filename=None):
        if filename is None:
            filename = self.main_path / 'database.xml'
        parsed = PaellaParser(filename)
        return parsed

    def start_schema(self):
        try:
            start_schema(self.conn)
        except AlreadyPresentError:
            print "primary tables already present"

    def import_all_families(self, dirname=None):
        if dirname is None:
            dirname = self.main_path / 'families'
        xmlfiles = dirname.listdir('*.xml')
        self.report_total_families(len(xmlfiles))
        while xmlfiles:
            familyxml = xmlfiles.pop(0)
            try:
                self.import_family(familyxml)
            except UnbornError:
                xmlfiles.append(familyxml)
                
            
        print 'import families from', dirname
        

    def import_family(self, filename):
        self.family.import_family_xml(filename)
        self.report_family_imported(filename.namebase)
        
    
    def import_all_profiles(self, dirname=None):
        if dirname is None:
            dirname = self.main_path / 'profiles'
        dirname = path(dirname)
        xmlfiles = dirname.listdir('*.xml')
        self.report_total_profiles(len(xmlfiles))
        for xmlfile in xmlfiles:
            self.profile.import_profile(xmlfile)
            self.report_profile_imported(xmlfile.namebase)
            
    def import_all_diskconfigs(self, dirname=None):
        if dirname is None:
            dirname = self.main_path / 'diskconfig'
        dirname = path(dirname)
        files = dirname.listdir()
        cursor = self.conn.cursor(statement=True)
        for diskconfig in files:
            name= diskconfig.basename()
            data = dict(name=name, content=file(diskconfig).read())
            cursor.insert(table='diskconfig', data=data)
            
        
    # here suite is a parsed xml object (find name)
    def make_suite(self, suite):
        current_suites = self.suitecursor.get_suites()
        if suite.name not in current_suites:
            apt_ids = [e.apt_id for e in suite.aptsources]
            self.suitecursor.make_suite(suite.name, apt_ids)
        else:
            raise RuntimeError , 'suite %s already exists' % suite

    # aptsources is the PaellaParser.aptsources attribute
    def import_apt_sources(self, aptsources):
        self.report_total_apt_sources(len(aptsources))
        for apt in aptsources:
            self.import_parsed_apt_source(apt)
            
    # here apt is an AptSourceParser object
    def import_parsed_apt_source(self, apt):
        self.report_importing_aptsrc(apt.apt_id)
        self.aptsrc.insert_apt_source_row(apt.apt_id, apt.uri, apt.dist,
                                          apt.sections, apt.local_path)
        self.aptsrc.insert_packages(apt.apt_id)
        self.report_aptsrc_imported(apt.apt_id)
        

    def _import_traits(self, suite, traitlist, dirname):
        self.report_total_traits(len(traitlist))
        missing = self._find_missing_packages(suite, traitlist, dirname)
        if missing:
            self.report_missing_packages(suite, missing)
            raise MissingPackagesError, report_missing_packages(suite, missing)
        else:
            while len(traitlist):
                trait = traitlist.pop(0)
#.........這裏部分代碼省略.........
開發者ID:BackupTheBerlios,項目名稱:paella-svn,代碼行數:103,代碼來源:main.py


注:本文中的family.Family.import_family_xml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。