Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
res.append(pkg)
if not res:
branches.append(package)
package_info = {}
for branch in branches:
package_info[branch] = [i for i in package_reqs[branch] if i in package_with_news]
return package_info
def get_co_branches(branches):
"""
Return corelated branches
"""
co_branches = []
for branch in branches:
for pkg, reqs in branches.iteritems():
if pkg == branch:
continue
if len(branches[branch]+reqs) != len(list(set(branches[branch]+reqs))):
co_branches.append(branch)
return list(set(co_branches))
def cross_packages(data):
"""
Return cross packages
"""
cross_branches = []
out, pkg_reqs = {}, {}
package_branches = get_branches(data)
_package_no_news, package_with_news = single_multi(data)
package_with_news = package_with_news+not_installed(data)
for package in package_with_news:
res = []
for pkg, reqs in package_branches.iteritems():
if package in reqs:
res.append(pkg)
if len(res) > 1:
cross_branches.append(package)
for package in package_with_news:
if package not in cross_branches:
version = pvector(package, data)[0][1]
pkg_reqs = save_version(pkg_reqs, data, package, version)
merged_reqs = merge_two_dicts(pkg_reqs, get_no_news_req(data))
for package in cross_branches:
reqs = []
for pkg, pkg_data in merged_reqs.iteritems():
add_reqs(reqs, pkg_data, pkg=package)
compatible = get_compatible([pkg[1] for pkg in pvector(package, data)], reqs)
if compatible:
out = save_ic(out, package, compatible=compatible[0])
return out
def get_comb_summary(data, packages, common_reqs):
"""
Return combination summary
"""
out = {}
for comb in list(itertools.product(*packages)):
pkg_reqs = {}
for package, version in comb:
pkg_reqs = save_version(pkg_reqs, data, package, version)
pkg_reqs = merge_two_dicts(common_reqs, pkg_reqs)
sumary = []
for package, version in comb:
reqs = []
for _pkg, pkg_data in pkg_reqs.iteritems():
add_reqs(reqs, pkg_data, pkg=package)
specifiers = specifiers_intersection(
[i for i in itertools.chain(*[req[1] for req in reqs])])
sumary.append(is_in_specifiers(version, specifiers))
if all(sumary):
sumary = 0
for package, version in comb:
sumary += pvector(package, data).index((package, version))
out[comb] = sumary
return out
def u_comb(data, packages, common_reqs):
"""
Return combination upgrade
"""
out = []
high = 0
comb_summary = get_comb_summary(data, packages, common_reqs)
for comb, summary in comb_summary.iteritems():
if summary > high:
high = summary
if high > 0:
reqs = []
for comb, summary in comb_summary.iteritems():
if summary == high:
reqs.append(comb)
for pkg, version in reqs[0]:
if 'installed_version' in data[pkg].keys() and \
data[pkg]['installed_version'] != version:
out.append((pkg, version))
return out
return None
def ibranch(data, fix=False):
"""
Return upgradeable versions of independent branch
"""
out = {}
no_news_req = get_no_news_req(data)
branches = get_branches(data)
_package_no_news, package_with_news = single_multi(data)
co_branches = get_co_branches(branches)
for branch in branches:
if branch in co_branches:
continue
if fix:
version = pvector(branch, data)[0][1]
pkg_reqs = save_version({}, data, branch, version)
common_reqs = merge_two_dicts(pkg_reqs, no_news_req)
packages = [pvector(pkg, data)[:2] \
for pkg in branches[branch] if pkg in package_with_news]
else:
common_reqs = no_news_req.copy()
packages = [pvector(branch, data)]+[pvector(pkg, data) \
for pkg in branches[branch] if pkg in package_with_news]
compatible = u_comb(data, packages, common_reqs)
if compatible:
for pkg, version in compatible:
out = save_ic(out, pkg, compatible=version)
return out
def p_upgrade(data, pkg, compatible=None, incompatible=None):
"""
Partial upgrade
"""
if compatible:
data[pkg]['upgradeable_version'] = compatible
if incompatible:
for version in incompatible:
if compatible and version not in compatible:
data = move_incompatible(data, [(pkg, version)])
elif not compatible:
data = move_incompatible(data, [(pkg, version)])
return data
def first_loop(data):
"""
Upgrade loop
"""
while True:
to_delete_hards = del_hards(data)
data = move_incompatible(data, to_delete_hards)
to_delete_no_news = del_no_news(data)
data = move_incompatible(data, to_delete_no_news)
to_delete_one_ver = del_one_ver(data)
data = move_incompatible(data, to_delete_one_ver)
phase_one_packages = phase_one(data)
for pkg, pkg_data in phase_one_packages.iteritems():
data = p_upgrade(data, pkg, compatible=pkg_data['compatible'],
incompatible=pkg_data['incompatible'])
cross_pkgs = cross_packages(data)
for pkg, pkg_data in cross_pkgs.iteritems():
data = p_upgrade(data, pkg, compatible=pkg_data['compatible'],
incompatible=pkg_data['incompatible'])
to_delete_noti = del_notinstalled(data)
data = move_incompatible(data, to_delete_noti)
i_branch = ibranch(data, fix=True)
for pkg, pkg_data in i_branch.iteritems():
data = p_upgrade(data, pkg, compatible=pkg_data['compatible'])
if all([not to_delete_hards, not to_delete_no_news, not to_delete_one_ver,
not phase_one_packages, not cross_pkgs, not to_delete_noti, not i_branch]):
break
return data
def main():
"""
main function
"""
os.environ["PYTHONWARNINGS"] = "ignore:DEPRECATION"
arguments = arg_parse()
packages_data = get_pkg_data()
packages_data = move_incompatible(packages_data, del_excls(packages_data, excludes))
packages_data = first_loop(packages_data)
i_branch = ibranch(packages_data)
for package, data in i_branch.iteritems():
if data['compatible']:
packages_data[package]['upgradeable_version'] = data['compatible']
check_co_branches(packages_data)
check_extras(packages_data)
if arguments.table:
sys.exit(print_table(packages_data))

Marek Chrastina
committed
if arguments.list:
sys.exit(print_list(packages_data))
if arguments.show is not None:
if arguments.show:
pkgs = arguments.show
else:
pkgs = packages_data
for pkg in pkgs:
pprint.pprint({pkg: packages_data[pkg]})
sys.exit(0)

Marek Chrastina
committed
if arguments.upgrade:
to_upgrade = []
for pkg in sorted(select_upkgs(packages_data, 'upgradeable_version')):
to_upgrade.append((pkg, packages_data[pkg]['upgradeable_version']))
upgrade_package(to_upgrade)

Marek Chrastina
committed
print "Done."