summaryrefslogtreecommitdiffstats
path: root/build_tools/bin/massupdate_linhes.py
blob: 2063f7b9b3c0b8838a6b6bcce151182e479b58d5 (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- coding: utf-8 -*-
import os
import re
import commands

def create_pkglist(repodir):
    group_list={}
    os.chdir(str(repodir))
    dir_list = os.listdir(".")
    for dir in dir_list:
        if os.path.isdir(dir):
            #print "found a dir:%s" %dir

            dir_walk = dir
            for root, dirs, files in os.walk(dir_walk):
                #print "walking %s,%s" %(root,dirs)
                for file in [f for f in files]:
                    if file == "PKGBUILD" :
                        topdir="%s/%s" %(repodir, root)
                        if "linhes_pkgbuild" in topdir:
                            if  ("core" in topdir) or ("extra" in topdir):
                                pass
                            else:
                                print "%s not LINHES" %topdir
                                print "skipping"
                                continue

                        currentfile = topdir + "/PKGBUILD"
                        if os.path.isfile(currentfile):
                            pkgname="unknown"
                            pkgversion="unknown"
                            pkgdescription="unknown"
                            pkggroup=[]
                            try:
                                f= open(currentfile,"r")
                                file_contents= f.readlines()
                                f.close()
                                for line in file_contents:
                                    if line.strip().startswith("pkgname"):
                                        pkgname=line.partition("=")[2].strip()

                                    elif line.strip().startswith("pkgver"):
                                        pkgversion=line.partition("=")[2]

                                    elif line.strip().startswith("pkgdesc"):
                                        pkgdescription=line.partition("=")[2]

                                    elif line.strip().startswith("groups"):
                                        l=line.partition("=")[2].strip()
                                        for c in ['(',')',"'"]:
                                            l = l.replace( c, '' )
                                        pkggroup=l.split()
                            except:
                                pass

                            #temptuple=(pkgname,topdir)
                            #group_list.append(temptuple)
                            group_list[pkgname] = (topdir,pkgversion)
                        #print repodir
                        #print root
                        #print dirs
                        #print file
    os.chdir("..")
    return group_list

def updatepkg(abslocation,linheslocation):
    print "\n\n"
    print "%s  - > %s "  %(abslocation, linheslocation)
    print "---------------------------------------------------------------"
    cmd = '''rsync -avchp -delete-after  --stats --exclude="src" %s/  %s'''   %(abslocation, linheslocation)
    totalfiles=0
    global    updated
    global failed
    global no_update
    rc,output = commands.getstatusoutput(cmd)
   # print output
    for line in output.split("\n"):
    #print line
        sline=line.strip()
        if line.startswith("Number of files transferred"):
            totalfiles=line.split(":")[1].strip()
            if rc == 0:
                #print totalfiles
                totalfiles = int(totalfiles.strip())
                if totalfiles >= 1 :
                   # print "total files transferred is more then 0"
                    cmd = "touch %s/.updated" %linheslocation
                    os.system(cmd)
                    updated = updated + 1
                else:
                    cmd = "touch %s/.no_update" %linheslocation
                    os.system(cmd)
                    no_update = no_update +1
            else:
                cmd = "touch %s/.updated_failed" %linheslocation
                os.system(cmd)
                failed = failed + 1

    print "  updated: %s " %updated
    print "no_update: %s " %no_update
    print "   failed: %s " %failed




skip_changelist="/tmp/update_list/changelist"
updatedlist="/tmp/update_list/updatedlist"
not_in_abs="/tmp/update_list/not_in_abs"
matchlist="/tmp/update_list/matched"

skipfile = open(skip_changelist,"w")
updatefile = open(updatedlist,"w")
matchfile = open(matchlist,"w")
not_absfile = open(not_in_abs,"w")


abslist = create_pkglist("/var/abs")
linheslist = create_pkglist("/data/linhes_pkgbuild/abs")
global updated
global failed
global no_update
updated=0
failed=0
no_update=0

for pkgname, pkglocation_t in linheslist.iteritems():

    pkglocation=pkglocation_t[0]
    pkgversion=pkglocation_t[1].strip().rstrip('\n')
    #print pkgname, pkglocation
    if "mv-core" in pkglocation :
        continue
    if "mythtv" in pkglocation :
        continue
    if ("core" in pkglocation) or ("extra" in pkglocation):
        pass
    else:
        continue


    abslocation = ''
    try:
      abslocation = abslist[pkgname][0]
      absversion = abslist[pkgname][1].strip().rstrip('\n')
    except:
      #  print "pkg is not found in abs %s" %pkgname
        outline = "%s :  %s  \n" %(pkgname, pkglocation)
        not_absfile.write(outline)
        continue


    #print "ABSLOCATION  %s" %abslocation
    #print "LINHES LOCATION %s" %pkglocation
    changelog = pkglocation + "/__changelog"
    if os.path.isfile(changelog):
       # print "%s: pkg has linhes changelog, skipping" %pkgname
        outline = "%s :  %s \n" %(pkgname, pkglocation)
        skipfile.write(outline)
    else:
	if absversion == pkgversion:
		outline = "%s: matched %s \n" %(pkgname,pkgversion)
		matchfile.write(outline)
	else:
            #print "%s: updating from ABS" %pkgname
            outline = '%s:\n %s,%s | %s,%s \n' %(pkgname, pkglocation, pkgversion,  abslocation, absversion)
            print outline
            updatefile.write(outline)
#            updatepkg(abslocation,pkglocation)



skipfile.close()
updatefile.close()
not_absfile.close()