-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrevertpatch.py
More file actions
45 lines (36 loc) · 1.14 KB
/
Copy pathrevertpatch.py
File metadata and controls
45 lines (36 loc) · 1.14 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019-03-15
@author: Byng Zeng
"""
import os
import subprocess
VERSION = '1.0.2'
AUTHOR = 'Byng.Zeng'
# ===============================================================
# API functions
# ===============================================================
def execute_shell(cmd):
return subprocess.check_output(cmd, shell=True) if cmd else None
# revert all of patch.
def revert_patches(path, gits):
for git, subject in gits.items():
get_log = 'git log --pretty=format:%s'
reset_hard = 'git reset --hard HEAD~'
git_path = os.path.join(path, git)
os.chdir(git_path)
while True:
res = execute_shell(get_log)
res = list(res.decode('utf-8').split('\n'))[0]
if res == subject:
break
else:
print('revert patch : %s : %s' % (git, res))
execute_shell(reset_hard)
def remove_src_files(path, srcs):
for src in srcs:
p = os.path.join(path, src)
if os.path.exists(p):
print('remove files :', src)
execute_shell('rm -rf %s' % p)