~cprov/uci-engine/1335753-glance-creds

« back to all changes in this revision

Viewing changes to cupstream2distro/cupstream2distro/packageinppamanager.py

  • Committer: Francis Ginther
  • Date: 2014-06-10 20:42:46 UTC
  • mto: This revision was merged to the branch mainline in revision 571.
  • Revision ID: francis.ginther@canonical.com-20140610204246-b1bsrik7nlcolqy7
Import lp:cupstream2distro rev 605.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright (C) 2012 Canonical
 
3
#
 
4
# Authors:
 
5
#  Didier Roche
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify it under
 
8
# the terms of the GNU General Public License as published by the Free Software
 
9
# Foundation; version 3.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
# details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along with
 
17
# this program; if not, write to the Free Software Foundation, Inc.,
 
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
19
 
 
20
import ConfigParser
 
21
import logging
 
22
import os
 
23
import re
 
24
 
 
25
from .branchhandling import _get_parent_branch
 
26
from .packageinppa import PackageInPPA
 
27
from .settings import PROJECT_CONFIG_SUFFIX
 
28
 
 
29
 
 
30
def _ensure_removed_from_set(target_set, content_to_remove):
 
31
    '''Silent removal from an existing set'''
 
32
    try:
 
33
        target_set.remove(content_to_remove)
 
34
    except KeyError:
 
35
        pass  # in case we missed the "build" step
 
36
 
 
37
 
 
38
def get_all_packages_uploaded():
 
39
    '''Get (package, version, rev, branch) of all packages uploaded'''
 
40
 
 
41
    # we do not rely on the .changes files but in the config file
 
42
    # because we need the exact version (which can have an epoch)
 
43
    result = set()
 
44
    source_package_regexp = re.compile("(.*).{}$".format(PROJECT_CONFIG_SUFFIX))
 
45
    for file in os.listdir('.'):
 
46
        substract = source_package_regexp.findall(file)
 
47
        if substract:
 
48
            version = _get_current_packaging_version_from_config(substract[0])
 
49
            rev = _get_current_rev_from_config(substract[0])
 
50
            branch = _get_parent_branch(substract[0])
 
51
            result.add((substract[0], version, rev, branch))
 
52
    return result
 
53
 
 
54
 
 
55
def get_packages_and_versions_uploaded():
 
56
    '''Get (package, version) of all packages uploaded. We can have duplicates'''
 
57
 
 
58
    # we do not rely on the .changes files but in the config file
 
59
    # because we need the exact version (which can have an epoch)
 
60
    result = set()
 
61
    source_package_regexp = re.compile("(.*).{}.*$".format(PROJECT_CONFIG_SUFFIX))
 
62
    for file in os.listdir('.'):
 
63
        substract = source_package_regexp.findall(file)
 
64
        if substract:
 
65
            config = ConfigParser.RawConfigParser()
 
66
            config.read(file)
 
67
            result.add((substract[0], config.get('Package', 'packaging_version')))
 
68
    return result
 
69
 
 
70
 
 
71
def update_all_packages_status(packages_not_in_ppa, packages_building, packages_failed, particular_arch=None):
 
72
    '''Update all packages status, checking in the ppa'''
 
73
 
 
74
    for current_package in (packages_not_in_ppa.union(packages_building)):
 
75
        logging.info("current_package: " + current_package.source_name + " " + current_package.version)
 
76
        package_status = current_package.get_status(particular_arch)
 
77
        if package_status != None:  # global package_status can be 0 (building), 1 (failed), 2 (published)
 
78
            # if one arch building, still considered as building
 
79
            if package_status == PackageInPPA.BUILDING:
 
80
                _ensure_removed_from_set(packages_not_in_ppa, current_package)  # maybe already removed
 
81
                packages_building.add(current_package)
 
82
            # if one arch failed, considered as failed
 
83
            elif package_status == PackageInPPA.FAILED:
 
84
                _ensure_removed_from_set(packages_building, current_package)  # in case we missed the "build" step
 
85
                _ensure_removed_from_set(packages_not_in_ppa, current_package)  # in case we missed the "wait" step
 
86
                packages_failed.add(current_package)
 
87
            elif package_status == PackageInPPA.PUBLISHED:
 
88
                _ensure_removed_from_set(packages_building, current_package)  # in case we missed the "build" step
 
89
                _ensure_removed_from_set(packages_not_in_ppa, current_package)  # in case we missed the "wait" step
 
90
 
 
91
 
 
92
def _get_current_packaging_version_from_config(source_package_name):
 
93
    '''Get current packaging version from the saved config'''
 
94
    config = ConfigParser.RawConfigParser()
 
95
    config.read("{}.{}".format(source_package_name, PROJECT_CONFIG_SUFFIX))
 
96
    return config.get('Package', 'packaging_version')
 
97
 
 
98
 
 
99
def _get_current_rev_from_config(source_package_name):
 
100
    '''Get current tip revision from the saved config'''
 
101
    config = ConfigParser.RawConfigParser()
 
102
    config.read("{}.{}".format(source_package_name, PROJECT_CONFIG_SUFFIX))
 
103
    return config.get('Branch', 'rev')