-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalsatool
executable file
·1557 lines (1450 loc) · 58 KB
/
alsatool
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/python
# -*- Python -*-
"""HG ALSA Tool
Do operations on ALSA GIT repositories.
Usage:
%(PROGRAM)s [options] command
"""
import os
import sys
import getopt
import re
import config
from traceback import print_exc
from shutil import rmtree, copyfile
from rfc822 import parsedate_tz
from utils import git_repo, git_system, git_popen, diff_compare, \
git_read_commits, raw_subject, eprint, tmpdir, tmpfile, package, \
to_kernel_file
from drivermerge import analyze_diff, driver_merge, compare_trees, try_to_merge
VERSION="2.0"
PROGRAM = sys.argv[0]
BACKGROUND = None
def sendmail(to, subj, body, cc=None, from1='[email protected]'):
from time import time
from smtplib import SMTP
from email.MIMEText import MIMEText
from email.Header import Header
if type(to) == type(''):
to = [to]
msg = MIMEText(body.encode('utf8'), 'plain', 'UTF-8')
msg['Subject'] = Header(subj.encode('utf8'), 'UTF-8')
msg['Message-Id'] = '<alsatool%[email protected]' % time()
msg['From'] = from1
msg['To'] = to[0]
if cc:
msg['Cc'] = cc.join(', ')
s = SMTP()
s.connect(config.SMTP_SERVER)
s.sendmail(from1, to, msg.as_string())
s.close()
def selectrepos(repos):
if repos is None or len(repos) == 0:
return config.REPOSITORIES[:]
else:
neg = repos[0][0] == '-'
if neg:
negres = config.REPOSITORIES[:]
for repo in repos:
if (neg and repo[0] != '-') or \
(not neg and repo[0] == '-'):
raise ValueError, "inverted and non-inverted repo specifications cannot be mixed!"
if neg:
negres.remove(repo[1:])
if neg:
repos = negres
for repo in repos:
if not repo in config.REPOSITORIES:
raise ValueError, "repository '%s' is unknown" % repo
return repos
def xlist(argv=None):
s = ''
for i in config.REPOSITORIES:
s += i + ' '
print(s[:-1])
def git(repo, dir=None):
if dir is None:
dir = config.ROOT + '/' + repo
return "git --work-tree=%s --git-dir=%s" % (dir, dir + '/.git')
def clone(argv=None):
repos = selectrepos(argv)
for repo in repos:
print("clone", repo)
def diff(argv=None):
repos = selectrepos(argv)
first = True
for repo in repos:
if not first:
print
first = False
print("%s" % repo)
print("*"*len(repo))
pull([repo])
if git_system(repo, "--no-pager diff origin/master..master"):
raise ValueError, "diff %s" % repo
def pull(argv=None):
repos = selectrepos(argv)
for repo in repos:
if git_system(repo, "checkout master"):
raise ValueError, "checkout %s" % repo
os.chdir(config.ROOT + '/' + repo)
if git_system(repo, "pull origin master"):
raise ValueError, "pull %s" % repo
def push(argv=None):
repos = selectrepos(argv)
for repo in repos:
if git_system(repo, "checkout master"):
raise ValueError, "checkout %s" % repo
if git_system(repo, "push --tags origin master:refs/heads/master"):
raise ValueError, "push %s" % repo
def version_sort(tags):
tags1 = []
tags2 = {}
for tag in tags:
tag = tag.strip()
if tag == "tip" or tag == "master":
continue
try:
t = tag.split('.')
if len(t) == 3:
a, b, c = t
d = None
elif len(t) == 4:
a, b, c, d = t
else:
print 'Ignoring tag:', repr(tag), repr(t)
raise ValueError
if a[0] != 'v':
print 'Ignoring tag:', repr(tag), repr(t)
raise ValueError
a = int(a[1:])
b = int(b)
idx = 0
while idx < len(c) and ord(c[idx]) <= ord('9'):
idx += 1
c1 = int(c[:idx])
c2 = c[idx:]
if c2 == '':
c2 = '01'
if not d is None:
c2 += d
elif c2.startswith('rc'):
c2 = '00' + c2
else:
c2 = '02' + c2
str = "%08i.%08i.%08i.%s" % (a, b, c1, c2)
tags1.append(str)
tags2[str] = tag
except:
from traceback import print_exc
print_exc()
pass
tags1.sort()
res = []
for tag in tags1:
res.append(tags2[tag])
if len(res) > 0:
return res
return None
def showchanges1(repos, tag=None):
res = {}
if tag == "last":
tag = None
for repo in repos:
if repo == 'alsa':
continue
res[repo] = []
mytag = tag
if not mytag:
tags = version_sort(os.popen("%s tag" % git(repo)).readlines())
if not tags:
raise ValueError, "cannot obtain tags for repo %s" % repo
mytag = tags[-1]
fp = os.popen("%s diff --stat %s..HEAD" % (git(repo), mytag))
while 1:
line = fp.readline()
if not line or line.find('|') <= 0:
break
a, b = line.split('|')
a = a.strip()
if a in ['.hgignore', '.hgtags']:
continue
if a.endswith('.gitignore'):
continue
if config.VERBOSE:
print(' ', line.strip())
res[repo].append(a)
del fp
return res
def showchanged(argv=None):
if argv == None:
tag = "last"
repos = selectrepos(None)
else:
tag = argv[0]
repos = selectrepos(argv[1:])
res = showchanges1(repos, tag)
for repo in res:
print('Repository %s has %s changed files' % (repo, len(res[repo])))
if config.VERBOSE:
print(' ', line.strip())
def release1(repo, tag):
print('')
print('Repository %s' % repo)
print(''.rjust(11 + len(repo), '*'))
version = tag[1:]
pull([repo])
if repo == 'alsa-driver':
pull(['alsa-kmirror'])
files = []
if repo == 'alsa-driver':
lines = open(config.ROOT + '/' + repo + '/configure.in').readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith('CONFIG_SND_VERSION="'):
lines[idx] = 'CONFIG_SND_VERSION="%s"\n' % version
print(lines[idx][:-1])
break
open(config.ROOT + '/' + repo + '/configure.in', "w+").write(''.join(lines))
os.chdir(config.ROOT + '/' + repo)
if os.path.exists('include/version.h'):
os.remove('include/version.h')
if os.system("make ALSAKERNELDIR=../alsa-kernel all-deps"):
raise ValueError, "make"
if os.system("aclocal"):
raise ValueError, "aclocal"
if os.system("autoconf"):
raise ValueError, "autoconf"
if os.system("./configure --with-debug=full --with-isapnp=yes --with-sequencer=yes --with-kernel=%s" % (config.ROOT + '/alsa-kernel')):
raise ValueError, "configure"
if os.system("make -C include/sound version.h"):
raise ValueError, "include/sound/version.h"
files.append('configure.in')
elif repo in ['alsa-lib', 'alsa-plugins', 'alsa-utils',
'alsa-firmware', 'alsa-oss']:
lines = open(config.ROOT + '/' + repo + '/configure.ac').readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith('AC_INIT(%s, ' % repo):
lines[idx] = 'AC_INIT(%s, %s)\n' % (repo, version)
print(lines[idx][:-1])
break
open(config.ROOT + '/' + repo + '/configure.ac', "w+").write(''.join(lines))
files.append('configure.ac')
elif repo in ['tinycompress']:
lines = open(config.ROOT + '/' + repo + '/configure.ac').readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith('AC_INIT([%s], ' % repo):
lines[idx] = 'AC_INIT([%s], [%s])\n' % (repo, version)
print(lines[idx][:-1])
break
open(config.ROOT + '/' + repo + '/configure.ac', "w+").write(''.join(lines))
files.append('configure.ac')
elif repo == 'alsa-tools':
lines = open(config.ROOT + '/' + repo + '/Makefile').readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith("VERSION = "):
lines[idx] = "VERSION = %s\n" % version
print(lines[idx][:-1])
break
open(config.ROOT + '/' + repo + '/Makefile', "w+").write(''.join(lines))
files.append('Makefile')
elif repo == 'alsa-python':
lines = open(config.ROOT + '/' + repo + '/setup.py').readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith("VERSION='"):
lines[idx] = "VERSION='%s'\n" % version
print(lines[idx][:-1])
break
open(config.ROOT + '/' + repo + '/setup.py', "w+").write(''.join(lines))
files.append('setup.py')
lines = open(config.ROOT + '/' + repo + '/PKG-INFO').readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith("Version: "):
lines[idx] = "Version: %s\n" % version
print(lines[idx][:-1])
break
open(config.ROOT + '/' + repo + '/PKG-INFO', "w+").write(''.join(lines))
files.append('PKG-INFO')
os.chdir(config.ROOT + '/' + repo)
if not repo in ['alsa-ucm-conf', 'alsa-topology-conf']:
for file in files:
if os.system("git add %s" % file):
raise ValueError, "git add %s" % file
if os.system('git commit -m "Release %s\n\nSigned-off-by: Jaroslav Kysela <[email protected]>\n"' % tag):
raise ValueError, "git commit"
if not repo in ['alsa-driver']:
if os.system('git tag %s -a -m "Release %s\n\nSigned-off-by: Jaroslav Kysela <[email protected]>\n"' % (tag, tag)):
raise ValueError, "git tag"
else:
if os.system('git branch -l %s %s' % tag):
raise ValueError, "git new branch"
def release(argv):
if argv == None or argv[0][0] != 'v':
raise ValueError, "specify release version in tag form"
tag = argv[0]
argv = argv[1:]
if len(argv) == 0:
repos = selectrepos(None)
elif argv[0] == 'auto':
res = showchanges1(selectrepos(None))
repos = res.keys()
else:
repos = selectrepos(argv)
if 'alsa' in repos:
repos.remove('alsa')
if 'alsa-kmirror' in repos:
repos.remove('alsa-kmirror')
print('Doing release for: %s' % ','.join(repos))
for repo in repos:
release1(repo, tag)
def _to_changes_log(str, file, module):
f = ''
log = ''
if module == 'alsa-driver':
f = config.ROOT + '/alsa-kmirror/' + file
if not os.path.exists(f):
f = ''
if not f:
f = config.ROOT + '/' + module + '/' + file
if os.path.exists(f):
if not os.path.isdir(f):
fp = open(f)
lines = fp.readlines()
while lines[0] in ['/*\n', ' *\n']:
del lines[0]
nlines = []
for line in lines:
if line.startswith('MODULE_DESCRIPTION'):
nlines.append(line)
lines = nlines + lines
log = '>>> ' + '>>> '.join(lines[:15])
fp.close()
fp = open("/tmp/changes-log.txt", "a+")
fp.write(str + "\n")
if log:
fp.write(log)
fp.close()
def _merge_members(regex, members, module='alsa-driver', nice=False):
def mgo(file, module):
if module == 'alsa-driver':
if file.startswith('/acore'):
file = '/' + file[2:]
elif file.startswith('/mirror/sound'):
file = file[13:]
elif file.startswith('/mirror/include/sound'):
file = '/include' + file[21:]
elif file.startswith('/mirror/Documentation/sound/alsa/'):
file = '/Documentation' + file[32:]
res = regex.search(module, file)
if res != 'ERROR':
return res
if file.endswith('/.cvsignore'):
return 'IGNORE'
if file.endswith('/.hgignore'):
return 'IGNORE'
if file.endswith('/.gitignore'):
return 'IGNORE'
if file.endswith('/.hgtags'):
return 'IGNORE'
if file.endswith('/Makefile.am'):
return file
if file.endswith('/Makefile'):
return file
return 'ERROR'
changes = []
result = []
for file in members:
file = "/" + file
while file != '':
result1 = mgo(file, module)
if result1 == 'ERROR':
found = False
for a in config.GERRORSA:
if a[0] == module and a[1] == file:
found = True
break
if not found:
config.GERRORS += 1
config.GERRORSA.append((module, file))
result1 = ''
if result1 != '':
file = ''
changes.append(result1)
else:
i = file.rfind('/')
if i < 0:
file = ''
else:
file = file[0:i]
i = 0
while i < len(changes):
j = 0
while j < len(changes):
if i != j and changes[i] == changes[j]:
del changes[j]
i = -1
break
j += 1
i += 1
xresult = ''
maxc = 70
if nice:
maxc = 61
for i in changes:
if len(i) + len(xresult) > maxc:
result.append(xresult)
xresult = ''
if xresult == '':
xresult = i
else:
xresult = xresult + ',' + i
if xresult != '':
result.append(xresult)
if len(result) > 1 and nice:
return []
elif len(result) > 0 and nice:
result[0] = "Modules: " + result[0]
result.append('')
return result
def changes(argv):
def rev_to_dot(rev):
if rev[0] == 'v':
return rev[1:]
else:
return rev
def print_underline(c, str):
i = len(str)
while i > 0:
sys.stdout.write(c)
i -= 1
print
def store_changes(changes, logs, module, xrev):
if module == 'alsa-kmirror':
module = 'alsa-driver'
for a in logs:
a['xrev'] = xrev
a['module'] = module
changes.append(a)
def merge_members(changes):
res = {}
try:
os.remove("/tmp/changes-log.txt")
except OSError:
pass
for change in changes:
module = change['module']
if not res.has_key(module):
res[module] = {}
members = _merge_members(regex, change['files'], module)
if len(members) == 0:
continue
members = members[0]
mems = members.split(',')
for mem in mems:
if mem == 'IGNORE':
continue
if not res[module].has_key(mem):
res[module][mem] = []
res[module][mem].append(change)
if config.GERRORS > 0:
for a in config.GERRORSA:
str = 'Cannot identify file "%s" from module %s' % (a[1], a[0])
_to_changes_log(str, a[1], a[0])
print(str)
print('^^^ {see /tmp/changes-log.txt file}')
print('Bailing out...')
sys.exit(1);
return res
def get_items(allitems):
items = []
idx = 0
for item in ['Sound Core', 'ALSA Core']:
items.append([item])
idx += 1
core = idx
items.append([]) # Core
midlevel = idx + 1
items.append([]) # Midlevel
all = idx + 2
items.append(allitems)
items[all].sort()
for item in items[all]:
if item.find('Core') >= 0:
items[core].append(item)
if item.find('Midlevel') >= 0:
items[midlevel].append(item)
if item.find('API') >= 0:
items[midlevel].append(item)
idx1 = core
while idx1 < all:
for item in items[idx1]:
items[all].remove(item)
idx1 += 1
for items1 in items[:idx]:
for item in items1:
idx1 = idx
while idx1 < len(items):
if item in items[idx1]:
items[idx1].remove(item)
idx1 += 1
return items
def check_tag(tags, rev):
for tag in tags:
a = tag.strip()
if len(a) != len(rev):
continue
if a == rev:
return True
return False
def esc(str):
return str.replace('>', '>').replace('<', '<').replace('&', '&')
def mediawiki_header(fp, title):
fp.write("""\
<mediawiki version="0.3" xml:lang="en">
<page>
<title>%s</title>
<revision>
<id>1</id>
<contributor><username>Perex</username><id>2</id></contributor>
<text xml:space="preserve">
{| align="right"\n| __TOC__\n|}
""" % title)
def mediawiki_footer(fp):
fp.write("""\
</text>
</revision>
</page>
</mediawiki>
""")
try:
rev1 = argv[0]
rev2 = argv[1]
except:
sys.stderr.write('Please, specify oldtag and newtag\n')
sys.exit(1)
from comments import CommentRegex
regex = CommentRegex()
changes = []
fullset = config.REPOSITORIES
fromrev = {}
p = re.compile('.*[a-z]+')
rev2last = rev2
if not p.match(rev2[1:]):
rev2last = rev2 + 'zzzzz'
for module in fullset:
xrev = rev1
fp = os.popen("%s tag 2> /dev/null" % git(module))
tags = fp.readlines()
fp.close()
fp = os.popen("%s branch 2> /dev/null" % git(module))
branches = fp.readlines()
fp.close()
for b in branches:
tags.append(b[2:])
if not check_tag(tags, rev2):
continue
tags1 = []
base = rev2 == 'HEAD' and 'v999.999.999' or rev2
while not check_tag(tags, xrev):
if rev2[0] != 'v':
base = 'v9.9.9'
elif rev2[-3:-1] == "rc":
base = rev2[:-3]
elif rev2[-1:] >= "a":
base = rev2[:-1]
for tag in tags:
a = tag.strip()[:-1]
if a >= rev2last:
continue
if tag.strip() != rev2:
tags1.append(tag)
tags1 = version_sort(tags1)
if tags1 is None:
tags1 = []
elif len(tags1) != 0:
xrev = tags1[len(tags1)-1]
break
major, minor, subminor = base.split('.')
subminor = int(subminor) - 1
if subminor < 0:
raise ValueError
base = "%s.%s.%s" % (major, minor, subminor)
fromrev[module] = xrev
commits = git_read_commits(module, xrev, rev2)
store_changes(changes, commits, module, xrev)
res = merge_members(changes)
modules1 = res.keys()
modules = []
groups = {}
for module in fullset:
if module in modules1:
modules.append(module)
rev = fromrev[module]
if not groups.has_key(rev):
groups[rev] = []
groups[rev].append(module)
short = ''
long = ''
long_hda = ''
long_soc = ''
rev = None
for rev in groups:
str = '=Changelog between %s and %s releases=\n' % (rev_to_dot(rev), rev_to_dot(rev2))
short += str
for module in groups[rev]:
short += '==%s==\n' % module
items = get_items(res[module].keys())
for items1 in items:
for b in items1:
if not res[module].has_key(b):
continue
short += '===%s===\n' % esc(b)
for a in res[module][b]:
log = a['comment'].splitlines()[0]
if log[:9] == 'Summary: ':
log = log[9:]
elif log[:8] == 'Summary:':
log = log[8:]
short += ': %s\n' % esc(log)
for rev in groups:
long += '=Detailed changelog between %s and %s releases=\n' % (rev_to_dot(rev), rev_to_dot(rev2))
long += str
for module in groups[rev]:
long += '==%s==\n' % module
items = get_items(res[module].keys())
for items1 in items:
for b in items1:
if not res[module].has_key(b):
continue
hdaflag = b.startswith('HDA ') and module == 'alsa-driver'
socflag = (b.startswith('SoC ') or b.startswith('Soc ')) and module == 'alsa-driver'
long += '===%s===\n' % esc(b)
if hdaflag:
long += ': see [[Detailed HDA changes %s %s]]\n' % (rev1, rev2)
long_hda += '===%s===\n' % esc(b)
if socflag:
long += ': see [[Detailed SoC changes %s %s]]\n' % (rev1, rev2)
long_soc += '===%s===\n' % esc(b)
for a in res[module][b]:
log = a['comment'].splitlines()
first = "-"
for l in log:
if l[:13] == "Patch-level: ":
continue
if l[:13] == "Patch-Level: ":
continue
if l[:15].lower() == "signed-off-by: ":
continue
if l[:10].lower() == "acked-by: ":
continue
if l[:6].lower() == "from: ":
continue
if l[:4].lower() == "cc: ":
continue
if hdaflag:
long_hda += ': %s %s\n' % (first, esc(l))
elif socflag:
long_soc += ': %s %s\n' % (first, esc(l))
else:
long += ': %s %s\n' % (first, esc(l))
first = " "
print("Changes are in /tmp/alsa-changes.wiki")
fp = open('/tmp/alsa-changes.wiki', 'w+')
mediawiki_header(fp, 'Changes %s %s' % (rev1, rev2))
fp.write('[[Detailed changes %s %s]]\n' % (rev1, rev2))
fp.write(short)
mediawiki_footer(fp)
fp = open('/tmp/alsa-changes1.wiki', 'w+')
mediawiki_header(fp, 'Detailed changes %s %s' % (rev1, rev2))
fp.write(long)
mediawiki_footer(fp)
idx = 2
if rev:
for id in [('HDA', long_hda), ('SoC', long_soc)]:
fp = open('/tmp/alsa-changes%s.wiki' % idx, 'w+')
mediawiki_header(fp, 'Detailed %s changes %s %s' % (id[0], rev1, rev2))
str = '=Detailed %s changelog between %s and %s releases=\n' % (id[0], rev_to_dot(rev), rev_to_dot(rev2))
fp.write(str + '\n')
module = 'alsa-driver'
fp.write('==%s==\n' % module)
fp.write(id[1])
mediawiki_footer(fp)
idx += 1
def usage(code=0, msg=''):
print(__doc__ % globals())
print('Where options is:')
for opt in OPTS:
print
if opt[0]:
print("\t-%s %s" % (opt[0].replace(':', ''), opt[3]))
print("\t--%s %s" % (opt[1].replace('=', ''), opt[3]))
print("\t\t%s" % opt[4].replace('\n', '\t\t'))
print('')
print('Where command is:')
for cmd in CMDS:
print('')
print("\t%s %s" % (cmd[0], cmd[2]))
print("\t\t%s" % cmd[3].replace('\n', '\n\t\t'))
if msg:
print('')
print(msg)
sys.exit(code)
def root(argv):
if argv == None:
eprint('Specify root directory.')
sys.exit(1)
config.ROOT=os.path.abspath(argv)
def verbose(argv):
config.VERBOSE=True
def extpick(argv, edit=False, sign=False, interactive=True):
if argv[0] in ['-s', '--signoff']:
sign = True
del argv[0]
sign = sign and ' --signoff' or ''
interactive = interactive and ' -i' or ''
repo = os.path.abspath(argv[0])
commit = argv[1]
tmpdir = ".extpick"
if not os.path.exists(tmpdir):
os.mkdir(tmpdir)
if git_system('.', "format-patch -k --stdout --full-index %s~1..%s > %s" % (commit, commit, tmpdir + '/format-patch')):
raise ValueError, "format-patch"
lines = open(tmpdir + "/format-patch").readlines()
for idx in range(0, len(lines)):
if lines[idx].startswith('Subject: '):
a = lines[idx][8:].strip()
if not a.upper().startswith('[ALSA]') and \
not a.upper().startswith('ALSA:') and \
not a.upper().startswith('[SOUND]') and \
not a.upper().startswith('SOUND:') and \
not a.upper().startswith('ASOC:'):
if a.upper().startswith('SOUNDS: '):
a = a[8:].strip()
lines[idx] = 'Subject: sound: ' + a + '\n'
break
open(tmpdir + "/format-patch", "w+").write(''.join(lines))
if edit:
editor = os.environ.has_key('EDITOR') and os.environ['EDITOR'] or 'vi'
copyfile(tmpdir + "/format-patch", tmpdir + "/format-patch.orig")
os.system("%s %s" % (editor, tmpdir + "/format-patch"))
if not os.system("diff %s %s > /dev/null" % (tmpdir + "/format-patch", tmpdir + "/format-patch.orig")):
rmtree(tmpdir)
return "nochanges"
res = os.system("git am%s%s -3 --keep %s" % (sign, interactive, tmpdir + '/format-patch'))
#if os.system("git --work-tree=%s --git-dir=%s mailinfo -u %s %s < %s > %s" % (repo, repo + '/.git', tmpdir + '/msg', tmpdir + '/patch', tmpdir + '/format-patch', tmpdir + '/info')):
# raise ValueError, "mail-info"
rmtree(tmpdir)
return res
def kmirrorpick(argv, edit=False, sign=False, interactive=True):
while argv:
if argv[0] in ['-s', '--signoff']:
sign = True
del argv[0]
elif argv[0] in ['-e', '--edit']:
edit = True
else:
break
sign = sign and ' --signoff' or ''
interactive = interactive and ' -i' or ''
repo = git_repo(argv[0])
commit = argv[1]
tmpdir = ".kmirrorpick"
if not os.path.exists(tmpdir):
os.mkdir(tmpdir)
if os.system("git --work-tree=%s --git-dir=%s format-patch -k --stdout --full-index %s~1..%s > %s" % (repo, repo + '/.git', commit, commit, tmpdir + '/format-patch')):
raise ValueError, "format-patch"
lines, addfiles, rmfiles = analyze_diff(open(tmpdir + "/format-patch"), full=True)
open(tmpdir + "/format-patch", "w+").write(''.join(lines))
if edit:
editor = os.environ.has_key('EDITOR') and os.environ['EDITOR'] or 'vi'
copyfile(tmpdir + "/format-patch", tmpdir + "/format-patch.orig")
os.system("%s %s" % (editor, tmpdir + "/format-patch"))
if not os.system("diff %s %s > /dev/null" % (tmpdir + "/format-patch", tmpdir + "/format-patch.orig")):
return "nochanges"
res = os.system("git am%s%s -3 --keep %s" % (sign, interactive, tmpdir + '/format-patch'))
if res == 256:
res = os.system("LANG=C patch -p2 < %s > %s" % (tmpdir + '/format-patch', tmpdir + '/patch.out'))
lines = open(tmpdir + '/patch.out').readlines()
sys.stdout.write(''.join(lines))
if res == 0:
for line in lines:
if line.startswith('patching file '):
os.system("git add %s" % line[13:])
os.system("git am -3 --resolved")
#if os.system("git --work-tree=%s --git-dir=%s mailinfo -u %s %s < %s > %s" % (repo, repo + '/.git', tmpdir + '/msg', tmpdir + '/patch', tmpdir + '/format-patch', tmpdir + '/info')):
# raise ValueError, "mail-info"
#rmtree(tmpdir)
return res
def edit(argv, remove=False):
commit = argv[0]
fp = os.popen("git log --pretty=oneline --reverse %s~1..HEAD" % commit)
commits = []
tmpdir = ".editmsg"
if not os.path.exists(tmpdir):
os.mkdir(tmpdir)
while 1:
line = fp.readline()
if not line:
break
commits.append(line.split(' ')[0])
open(tmpdir + '/commits', "w+").write('\n'.join(commits))
head = os.popen("git rev-parse HEAD").readline().strip()
print("Original HEAD is %s..." % head)
print("Removed commits are in %s..." % tmpdir + '/commits')
print("Resetting tree to %s..." % os.popen("git log --pretty=oneline %s~1..%s" % (commit, commit)).readline().strip())
if os.system("git reset --hard %s~1" % commit):
raise ValueError, "git reset"
first = True
for commit in commits:
if remove and first:
first = False
continue
res = extpick(['.', commit], edit=first, interactive=True)
if type(res) == type('') and res == "nochanges":
print("No changes, resetting back to %s..." % head)
sys.exit(os.system("git reset --hard %s" % head))
if res:
sys.stderr.write("Error, bailing out\n")
sys.exit(1)
first = False
rmtree(tmpdir)
def remove(argv):
edit(argv, remove=True)
def import_(argv):
from hashlib import sha1 as sha_new
def is_blacklisted(commit):
hexdigest = sha_new(os.popen("git diff %s~1..%s" % (commit, commit)).read(10*1024*1024)).hexdigest()
return hexdigest in blacklist
def do_blacklist(commit):
diff1 = os.popen("git diff %s~1..%s" % (commit['ref'], commit['ref'])).read(10*1024*1024)
digest = sha_new(diff1).hexdigest()
if not digest in blacklist:
subject = commit['comment'].splitlines()[0].strip()
open(".git/import-blacklist", "a+").write(digest + ' ' + subject + '\n')
else:
print('Already blacklisted...')
if os.path.exists('.dotest'):
sys.stderr.write('previous dotest directory .dotest still exists\n')
return 1
blacklist1 = open(".git/import-blacklist").readlines()
blacklist = []
for l in blacklist1:
blacklist.append(l[:l.find(' ')])
del blacklist1
branch = argv[0]
base = os.popen("git merge-base master %s" % branch).readline().strip()
log1 = git_read_commits('.', 'master', branch, reverse=True)
log2 = git_read_commits('.', base, 'master', reverse=True)
tomerge = []
skipcount = 0
for l1 in log1:
if l1.has_key('Merge'):
continue
subject1 = raw_subject(l1['comment'].splitlines()[0])
merged = False
blacklisted = False
for l2 in log2:
subject2 = raw_subject(l2['comment'].splitlines()[0])
if subject1 == subject2:
merged = True
break
if not merged and is_blacklisted(l1['ref']):
merged = True
blacklisted = True
if merged:
skipcount += 1
print("Already picked%s:" % (blacklisted and '/blacklisted' or ''))
print("** %s/%s %s" % (branch, l1['ref'][:7], l1['comment'].splitlines()[0][:-1]))
if not blacklisted:
print("** master/%s %s" % (l2['ref'][:7], l2['comment'].splitlines()[0][:-1]))
else:
tomerge.append(l1)
print('Already merged patches: %s' % skipcount)
print('Patches to be merged: %s' % len(tomerge))
for l1 in tomerge:
print l1['ref'], l1['comment'].splitlines()[0][:-1]
oldrev = os.popen("git rev-parse HEAD").readline().strip()
if extpick(['.', l1['ref']], sign=True, interactive=False):
if os.system("git am -3 --abort") or \
os.system("git reset --hard"):
raise ValueError
sys.stderr.write('An error occured... Skipping...\n')
sys.stderr.write('Error ref: %s\n' % l1['ref'])
rev = os.popen("git rev-parse HEAD").readline().strip()
if oldrev == rev:
sys.stdout.write('No change, do you want to black list this patch? (Y/ ) ')
sys.stdout.flush()
line = sys.stdin.readline()
if line.startswith('Y'):
do_blacklist(l1)
return 0
def getgitfile(url, file, size=1024):
from urllib import splithost
from httplib import HTTPS
if not url.startswith('https:'):
raise ValueError, "URL %s" % url
host, selector = splithost(url[6:])
h = HTTPS(host)
h.putrequest('GET', url + '/' + file)
h.endheaders()
h.getreply()
res = h.getfile().read(size)
h.close()
return res
def getorigin(repo = 'alsa-kernel'):
origin = getgitfile('https://git.alsa-project.org/http/%s.git' % repo, 'info/refs', size=8192)
for line in origin.splitlines():
a = line.strip().split('\t')
if a[1] == 'refs/heads/master':
origin = a[0]
break
origin = origin.strip()
if len(origin) != 40:
raise ValueError, "git.alsa-project.org is down?"
return origin
def mailit(msg, subject):
from email.MIMEText import MIMEText
import smtplib
import time
msg = MIMEText(msg, 'plain', 'utf-8')
msg['Subject'] = subject
msg['Message-Id'] = '<alsatool%[email protected]>' % time.time()
msg['From'] = '[email protected]'
msg['Reply-To'] = '[email protected]'
msg['To'] = '[email protected]'
s = smtplib.SMTP()
s.connect()
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.close()
print("An email to %s was sent!" % msg['To'])
def tolinus(argv):
from datetime import datetime
branch = argv[0]
if not branch in ["for-linus"]:
raise ValueError, "branch %s" % branch
today = datetime.today()
patch = "alsa-git-%s-%04i-%02i-%02i.patch" % (branch, today.year, today.month, today.day)
lines = """
Linus, please pull from:
git pull git://git.alsa-project.org/alsa-kernel.git %s
gitweb interface:
http://git.alsa-project.org/?p=alsa-kernel.git;a=shortlog;h=%s
The GNU patch is available at:
ftp://ftp.alsa-project.org/pub/kernel-patches/%s.gz
Additional notes: