-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_proprietary.py
executable file
·110 lines (82 loc) · 2.33 KB
/
copy_proprietary.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
import sys
import os.path
import re
import shutil
#--------------------
class GetVarValue:
STATE_LINE_FINISH = 'STATE_LINE_FINISH'
STATE_LINE_CONT = 'STATE_LINE_CONTINUE';
fileLines = [];
state = STATE_LINE_FINISH;
def __init__(self, fileLines):
self.fileLines = fileLines;
def parseMultiLines(self):
newLines = [];
tmpLine = '';
for line in self.fileLines:
line = line.strip();
if line.endswith('\\'):
line = line[:-1].strip() + ' ';
tmpLine += line;
else:
tmpLine += line;
newLines.append(tmpLine);
tmpLine = '';
if tmpLine:
newLines.append(tmpLine);
self.fileLines = newLines;
def parseVarAsList(self, varName):
prog = re.compile('^' + varName + '\s*\\+?=\s*(.+)$');
varValue = [];
for line in self.fileLines:
line = line.strip();
res = prog.search(line);
if not res:
continue;
valStr = res.group(1);
varValue.extend(valStr.split());
return varValue;
#--------------------
USAGE = os.path.basename(sys.argv[0]) + " DEVICE_FILE TOP_DIR OUT_DIR"
if len(sys.argv) != 4:
print "len(sys.argv) != 4"
print USAGE;
exit(1);
deviceFile=sys.argv[1];
topDir=sys.argv[2];
outDir=sys.argv[3];
if not os.path.isfile(deviceFile):
print deviceFile, "is not file"
print USAGE;
exit(2);
if not os.path.isdir(topDir):
print topDir, "is not dir"
print USAGE;
exit(2);
if not os.path.isdir(outDir):
print outDir, "is not dir"
print USAGE;
exit(2);
try:
f = open(deviceFile);
rawLines = f.read().splitlines();
f.close();
except IOError as e:
print "Error opening", deviceFile
print USAGE;
exit(2);
getVarValue = GetVarValue(rawLines);
getVarValue.parseMultiLines();
lines = getVarValue.parseVarAsList('PRODUCT_COPY_FILES');
for line in lines:
arr = re.split(':', line);
fromFile = topDir + '/' + arr[0];
toFile = outDir + '/' + arr[1];
print arr[1];
continue;
toFileDir = os.path.dirname(toFile);
if not os.path.isdir(toFileDir):
os.makedirs(toFileDir);
print 'Copying', fromFile, 'to', toFile;
shutil.copy(fromFile, toFile)