1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2012 Canonical
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.
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
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
25
from .branchhandling import _get_parent_branch
26
from .packageinppa import PackageInPPA
27
from .settings import PROJECT_CONFIG_SUFFIX
30
def _ensure_removed_from_set(target_set, content_to_remove):
31
'''Silent removal from an existing set'''
33
target_set.remove(content_to_remove)
35
pass # in case we missed the "build" step
38
def get_all_packages_uploaded():
39
'''Get (package, version, rev, branch) of all packages uploaded'''
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)
44
source_package_regexp = re.compile("(.*).{}$".format(PROJECT_CONFIG_SUFFIX))
45
for file in os.listdir('.'):
46
substract = source_package_regexp.findall(file)
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))
55
def get_packages_and_versions_uploaded():
56
'''Get (package, version) of all packages uploaded. We can have duplicates'''
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)
61
source_package_regexp = re.compile("(.*).{}.*$".format(PROJECT_CONFIG_SUFFIX))
62
for file in os.listdir('.'):
63
substract = source_package_regexp.findall(file)
65
config = ConfigParser.RawConfigParser()
67
result.add((substract[0], config.get('Package', 'packaging_version')))
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'''
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
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')
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')