mirrored from git://anongit.freedesktop.org/gstreamer/common
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathupdate_gst_modules_assets.py
executable file
·90 lines (75 loc) · 3.15 KB
/
update_gst_modules_assets.py
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
#!/usr/bin/env python3
import os
import shutil
import sys
import argparse
import subprocess
parser = argparse.ArgumentParser(prog="update-gstreamer-common-files",
description="Copy files that are common to several repository"
" to the right places in those.")
parser.add_argument("-m", "--commit-message",
help="git add modified files and commit the changes with this message.")
parser.add_argument('rootdir', metavar='rootdir', nargs=1,
help='The directory where to find GStreamer modules repoos.')
SCRIPTDIR = os.path.dirname(__file__)
FILES_TO_COPY = ['hooks/pre-commit.hook']
GETPLUGINSDIR = 'tests/check/getpluginsdir'
FILES_TO_COPY_PER_MODULE = {
'gstreamer': [],
'gst-plugins-base': [GETPLUGINSDIR],
'gst-plugins-good': [GETPLUGINSDIR],
'gst-plugins-ugly': [GETPLUGINSDIR],
'gst-plugins-bad': [],
'gst-libav': [],
'gst-editing-services': [GETPLUGINSDIR],
'gst-devtools': [(GETPLUGINSDIR, "validate/tests/")],
'gst-python': [],
}
if __name__ == "__main__":
options = parser.parse_args()
rootpath = options.rootdir[0]
if not os.path.exists(rootpath):
print("Please path the root directory where to find GStreamer modules repos"
" %s does not exists", rootpath)
exit(1)
summary = ""
for module, files in FILES_TO_COPY_PER_MODULE.items():
files += FILES_TO_COPY
repodir = os.path.abspath(os.path.join(rootpath, module))
if not os.path.exists(repodir):
print("Repo %s does not exists" % repodir)
exit(1)
if options.commit_message:
dirty = False
try:
dirty = subprocess.check_output('git status --porcelain --untracked-files=no'.split(' '),
cwd=repodir)
except Exception as e:
dirty = True
if dirty:
print("Can not commit %s as the repository is dirty." %
(repodir))
exit(1)
for f in files:
if isinstance(f, tuple):
destdir = os.path.join(repodir, f[1])
f = f[0]
else:
dirname = os.path.dirname(f)
destdir = os.path.join(repodir, dirname)
if destdir and not os.path.exists(destdir):
print("Making dir %s" % destdir)
os.makedirs(destdir, exist_ok=True)
dest = os.path.join(destdir, os.path.basename(f))
print("Copying %s to %s" %(f, dest))
shutil.copy(os.path.join(SCRIPTDIR, f), dest)
if options.commit_message:
subprocess.check_call(['git', 'add', os.path.abspath(dest)],
cwd=repodir)
if options.commit_message:
if subprocess.call('git diff-index --quiet --cached HEAD'.split(' '), cwd=repodir) != 0:
subprocess.call(['git', 'commit', '-m', options.commit_message], cwd=repodir)
if not summary:
summary = "Commited:\n"
summary += repodir + '\n'
print(summary)