Skip to content

Commit 14e858a

Browse files
author
Сосна Евгений
committed
Рефакторинг, исправленна ошибка пропуска файлов в папках с пробелами.
1 parent cdd938f commit 14e858a

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

pyv8unpack.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,37 @@
77
from os.path import exists
88
import logging
99
import tempfile
10+
import re
1011

1112
logging.basicConfig(level=logging.ERROR) # DEBUG => print ALL msgs
1213

14+
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
15+
16+
1317
def get_list_of_comitted_files():
1418
"""
1519
Retun a list of files abouts to be decompile
1620
"""
17-
1821
files = []
1922
output = []
2023
try:
21-
output = subprocess.check_output(['git','diff-index', '--cached','HEAD']).decode("utf-8")
24+
output = subprocess.check_output(['git','diff-index', '--name-status', '--cached','HEAD']
25+
).decode("utf-8")
2226
except subprocess.CalledProcessError:
2327
print("Error diff files get: trace %s" % subprocess.CalledProcessError.output)
2428
return files
2529

26-
2730
for result in output.split("\n"):
31+
logging.info(result)
2832
if result != '':
29-
result = result.split()
30-
if result[4] in ['A', 'M']:
31-
files.append(result[5])
33+
match = modified.match(result)
34+
if match:
35+
files.append(match.group('name'))
3236

3337
return files
3438

35-
def _copyonlydirs(path, names):
36-
result = []
37-
for name in names:
38-
if os.path.isfile(os.path.join(path, name, os.path.sep)):
39-
result.append(name)
40-
logging.info('Working in %s' % path)
41-
return result
4239

43-
def checker():
40+
def decompile():
4441
"""
4542
Main functions doing be decompile
4643
"""
@@ -54,7 +51,8 @@ def checker():
5451
#Find datapocessor files
5552
for filename in get_list_of_comitted_files():
5653
#Check the file extensions
57-
if filename[-3:] in ['epf', 'erf', '.py']:
54+
logging.info("file to check %s" % filename)
55+
if filename[-3:] in ['epf', 'erf']:
5856
dataprocessor_files.append(filename)
5957
logging.info("file %s" % filename)
6058
continue
@@ -64,6 +62,7 @@ def checker():
6462
dirsource = os.path.abspath(os.path.join(os.path.curdir, "src"))
6563
curabsdirpath = os.path.abspath(os.path.curdir)
6664
pathbin1c = "C:\\Program Files\\1cv82\8.2.17.153\\bin\\1cv8.exe"
65+
pathbin1c = "c:\\Program Files (x86)\\1cv8\\8.3.4.304\\bin\\1cv8.exe"
6766

6867
for filename in dataprocessor_files:
6968
print("file %s" % filename)
@@ -79,7 +78,6 @@ def checker():
7978
os.makedirs(dirsource)
8079
#для каждого файла определим новую папку.
8180
newsourcepath = os.path.join(dirsource, newdirname, basename)
82-
logging.info("create new dir %s" % newsourcepath)
8381
if not os.path.exists(newsourcepath):
8482
logging.info("create new dir %s" % newsourcepath)
8583
os.makedirs(newsourcepath)
@@ -90,20 +88,19 @@ def checker():
9088
formatstring = format('/C"decompile;pathtocf;%s;pathout;%s;ЗавершитьРаботуПосле;"' % (fullpathfile, newsourcepath))
9189
base = '/F"'+os.path.join(curabsdirpath,".git", "hooks","ibService")+'"'
9290
V8Reader = '/execute"'+os.path.join(curabsdirpath,".git", "hooks", "V8Reader.epf")+'"'
93-
logging.info(formatstring)
94-
logging.info(base)
95-
logging.info(V8Reader)
9691
tempbat = tempfile.mktemp(".bat")
97-
logging.info(tempbat)
92+
logging.info("formatstring is %s , base is %s, V8Reader is %s, temp is %s" % (formatstring, base, V8Reader, tempbat))
9893

9994
with open(tempbat, 'w', encoding='cp866') as temp:
10095
temp.write('@echo off\n')
10196
temp.write(format('"%s" %s /DisableStartupMessages %s %s'%(pathbin1c, base, V8Reader, formatstring)))
10297
temp.close()
10398
result = subprocess.check_call(['cmd.exe', '/C', tempbat])
104-
result = subprocess.check_call(['git', 'add', newsourcepath])
105-
#shutil.copyfile(filename, os.path.join(newsourcepath, fullbasename))
99+
result = subprocess.check_call(['git', 'add', '--all', newsourcepath])
100+
if not result == 0:
101+
logging.error(result)
102+
exit(result)
106103

107104

108105
if __name__ == '__main__':
109-
checker()
106+
decompile()

0 commit comments

Comments
 (0)