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


Python BuildService.getTargets方法代碼示例

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


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

示例1: ParticipantHandler

# 需要導入模塊: from buildservice import BuildService [as 別名]
# 或者: from buildservice.BuildService import getTargets [as 別名]
class ParticipantHandler(object):

    """ Participant class as defined by the SkyNET API """

    def __init__(self):
        self.obs = None
        self.oscrc = None

    def handle_wi_control(self, ctrl):
        """ job control thread """
        pass

    def handle_lifecycle_control(self, ctrl):
        """ participant control thread """
        if ctrl.message == "start":
            if ctrl.config.has_option("obs", "oscrc"):
                self.oscrc = ctrl.config.get("obs", "oscrc")

    def setup_obs(self, namespace):
        """ setup the Buildservice instance using the namespace as an alias
            to the apiurl """

        self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)

    def get_l10n_stats(self, source_project, target_project, package):
        tmp_dir_old = mkdtemp()
        tmp_dir_new = mkdtemp()

        old_ts_dir = tmp_dir_old + "/ts"
        new_ts_dir = tmp_dir_new + "/ts"
        target = self.obs.getTargets(str(source_project))[0]

        #get src.rpm as it contains all .ts files
        src_rpm = [rpm for rpm in self.obs.getBinaryList(
                source_project, target, package) if "src.rpm" in rpm]
        target_rpm = [rpm for rpm in self.obs.getBinaryList(
                target_project, target, package) if "src.rpm" in rpm]

        #download source and target rpms
        self.obs.getBinary(target_project, target, package, target_rpm[0],
                           tmp_dir_old + "/old.rpm")
        self.obs.getBinary(source_project, target, package, src_rpm[0],
                           tmp_dir_new + "/new.rpm")

        # extract rpms
        old_file = extract_rpm(tmp_dir_old + "/old.rpm", tmp_dir_old)
        new_file = extract_rpm(tmp_dir_new + "/new.rpm", tmp_dir_new)

        #rpm contains tar.bz2 and .spec file. Open and extract tar.bz2
        old_tar = tarfile.open(tmp_dir_old + '/' + old_file[0])
        old_tar.extractall(old_ts_dir)
        new_tar = tarfile.open(tmp_dir_new + '/' + new_file[0])
        new_tar.extractall(new_ts_dir)

        old_ts_files = {}
        for member in old_tar.members:
            # rpm directrory has .spec file
            if member.name.split('/')[1] == 'rpm':
                continue
            # "lang : path_to_ts_file" pair
            old_ts_files.update({member.name.split('/')[1] : member.name })

        new_ts_files = {}
        for member in new_tar.members:
            # rpm directrory has .spec file
            if member.name.split('/')[1] == 'rpm':
                continue
            # "lang : path_to_ts_file" pair
            new_ts_files.update({member.name.split('/')[1] : member.name })

        l10n_stats = {}
        for key in set(new_ts_files.keys()) & set(old_ts_files.keys()):
            _old_path = tmp_dir_old + "/ts/" +  old_ts_files[key]
            _new_path = tmp_dir_new + "/ts/" + new_ts_files[key]
            unit_diff = _make_ts_diff(_old_path, _new_path)
            l10n_stats.update({ key : unit_diff })
        l10n_stats.update({"removed_langs" : list(set(old_ts_files.keys()) - set(new_ts_files.keys())) })
        l10n_stats.update({"added_langs" : list(set(new_ts_files.keys()) - set(old_ts_files.keys())) })
        # possible removed strings
        l10n_stats.update({ "removed_strings" : [] })

        #check that -ts-devel package is not going out of sync
        src_pkg = package.replace("-l10n", "")

        #is there a package that is using -l10n pakcage already
        src_pkg = [rpm for rpm in self.obs.getPackageList(target_project) if src_pkg ==  rpm]

        if len(src_pkg) > 0:
            #get -ts-devel rpm
            src_ts_devel_rpm = [rpm for rpm in self.obs.getBinaryList(target_project, target, src_pkg[0]) if "-ts-devel" in rpm]
            if len(src_ts_devel_rpm) > 0:
                tmp_dir_ts = mkdtemp()
                self.obs.getBinary(target_project, target, src_pkg[0], src_ts_devel_rpm[0], tmp_dir_ts + "/orig.rpm")
                orig_ts_file = extract_rpm(tmp_dir_ts + "/orig.rpm", tmp_dir_ts, patterns="*.ts")
                original_units = factory.getobject(tmp_dir_ts + "/" + orig_ts_file[0])
                new_units = factory.getobject(tmp_dir_new + "/ts/" + new_ts_files['templates'])
                removed_units = set(original_units.getids()) - set(new_units.getids())
                l10n_stats.update({"removed_strings" : list(removed_units)})
                shutil.rmtree(tmp_dir_ts)

#.........這裏部分代碼省略.........
開發者ID:henriksa,項目名稱:boss-standard-workflow,代碼行數:103,代碼來源:check_l10n_update.py


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