-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbranchpointer
executable file
·157 lines (131 loc) · 5.25 KB
/
branchpointer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/python3
#set -o pipefail
#Copyright (c) 2009-2014 Peter M. Green and Adam D. Barratt
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of
#this software and associated documentation files (the "Software"), to deal in
#the Software without restriction, including without limitation the rights to
#use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
#of the Software, and to permit persons to whom the Software is furnished to do
#so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
import sys
import subprocess
#based on code by adsb from
#http://anonscm.debian.org/gitweb/?p=mirror/britney1.git;a=blob_plain;f=britney;h=094ec121d5bea3e68af76c493f2b9d91d734f45e;hb=HEAD
#I don't pretend to understand this perl code
def process_pkg_list(infile,outfile):
ifh = open(infile,'rb')
ofh = open(outfile,'wb')
subprocess.check_call(['perl',"-MAptPkg::Config '$_config'", '-e','''
my $versioning = $_config->system->versioning;
while (<>) {
$current .= $_;
if (/^Package: (.*)$/) {
$pkg = $1;
} elsif (/^Version: (.*)$/) {
$version = $1;
} elsif (/^\s*$/) {
$data{"$pkg"}{"$version"} = $current;
$pkg = ""; $version = ""; $current = "";
}
}
$data{"$pkg"}{"$version"} = $current if length $current;
for $pkg2 (sort keys %data) {
@versions = (reverse sort {$versioning->compare($a,$b)} keys %{$data{"$pkg2"}});
print "$pkg2 $versions[0]\n";
}
'''],stdin=ifh,stdout=ofh)
ifh.close()
ofh.close()
#set -o pipefail
MAINSUITE=sys.argv[1]
import os
SCRIPTDIR=os.path.dirname(os.path.realpath(__file__))
#source <($SCRIPTDIR/afpg_readconfig.py main:workingrepo main:gitdir main:tmp main:AFPGCONFIG $MAINSUITE:STAGINGSUITE $MAINSUITE:UPSTREAMSUITE)
#$SCRIPTDIR/afpg_readconfig.py main:workingrepo main:gitdir main:tmp main:AFPGCONFIG $MAINSUITE:STAGINGSUITE $MAINSUITE:UPSTREAMSUITE
import afpg_readconfig
workingrepo = afpg_readconfig.readconfigentry('main','workingrepo')
gitdir = afpg_readconfig.readconfigentry('main','gitdir')
tmp = afpg_readconfig.readconfigentry('main','tmp')
AFPGCONFIG = afpg_readconfig.readconfigentry('main','AFPGCONFIG')
STAGINGSUITE = afpg_readconfig.readconfigentry(MAINSUITE,'STAGINGSUITE')
UPSTREAMSUITE = afpg_readconfig.readconfigentry(MAINSUITE,'UPSTREAMSUITE')
import os
os.chdir(workingrepo)
import glob
def concatenatefiles(infiles,outfile):
ofh = open(outfile,'wb')
for infile in infiles:
ifh = open(infile,'rb')
ofh.write(ifh.read())
ifh.close()
ofh.close()
import collections
versions={}
for SUITE in [MAINSUITE,STAGINGSUITE,UPSTREAMSUITE]:
sources=glob.glob(workingrepo+'/dists/'+SUITE+'/*/source/Sources')
#print(tmp)
concatenatefiles(sources,tmp+'/sources-'+SUITE+'-catted')
process_pkg_list(tmp+'/sources-'+SUITE+'-catted', tmp+'/sources-'+SUITE+'-processed')
f = open(tmp+'/sources-'+SUITE+'-processed','r')
#make not found packages read as an empty string
v = collections.defaultdict(str)
for line in f:
(name,version) = line.strip().split(' ')
v[name] = version
versions[SUITE] = v
f.close()
#print(sources)
import re
def versiontotag(version):
tag = str(version)
tag = tag.replace(":","%")
tag = tag.replace("~","_")
tag = re.sub('\.(?=\.|$|lock$)','.#',tag)
return tag
wl = open(AFPGCONFIG+'/whitelist.import')
for PACKAGE in wl:
PACKAGE = PACKAGE.strip()
print(repr(PACKAGE))
if len(PACKAGE) > 0:
MAINVERSION=versions[MAINSUITE][PACKAGE]
STAGINGVERSION=versions[STAGINGSUITE][PACKAGE]
DEBVERSION=versions[UPSTREAMSUITE][PACKAGE]
#print(PACKAGE)
print('main version '+MAINVERSION)
print('staging version '+STAGINGVERSION)
print('deb version '+DEBVERSION)
if PACKAGE[0:3] == 'lib':
PACKAGEDIR=PACKAGE[0:4]+'/'+PACKAGE
else:
PACKAGEDIR=PACKAGE[0:1]+'/'+PACKAGE
os.chdir(gitdir+'/'+PACKAGEDIR)
f = open('.git/HEAD','r')
contents = f.read()
f.close()
if contents[0:4] == 'ref:':
#faster way to detach
#print('foo',flush=True)
os.system('git update-ref --no-deref HEAD $(git rev-parse --verify HEAD > /dev/null 2> /dev/null ) >/dev/null 2>/dev/null || true')
#print('bar',flush=True)
#git checkout -q --detach || true
if len(MAINVERSION) != 0:
MAINTAG=versiontotag(MAINVERSION)
subprocess.check_call(['git','branch','-f',MAINSUITE,MAINTAG])
if len(STAGINGVERSION) != 0:
STAGINGTAG=versiontotag(STAGINGVERSION)
subprocess.check_call(['git','branch','-f',STAGINGSUITE,STAGINGTAG])
if len(DEBVERSION) != 0:
DEBTAG=versiontotag(DEBVERSION)
subprocess.check_call(['git','branch','-f',UPSTREAMSUITE,DEBTAG])
wl.close()