Skip to content
This repository was archived by the owner on Oct 25, 2018. It is now read-only.

Commit 1a07da5

Browse files
author
Сосна Евгений
committed
Исправленна работа с кодировками.
Добавленны тесты.
1 parent 0706622 commit 1a07da5

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

pyv8unpack.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,20 @@ def decompile(list_of_files, source=None, platform=None):
194194
logging.debug("formatstring is %s , base is %s, V8Reader is %s, temp \
195195
is %s" % (formatstring, base, V8Reader, tempbat))
196196

197-
198197
with open(tempbat, 'w', encoding='cp866') as temp:
199198
temp.write('@echo off\n')
200-
temp.write(format('"%s" %s /DisableStartupMessages %s %s'%(pathbin1c, base, V8Reader, formatstring)))
199+
temp.write(format('"%s" %s /DisableStartupMessages %s %s' % (pathbin1c,
200+
base, V8Reader, formatstring))
201+
)
201202
temp.close()
202203
result = subprocess.check_call(['cmd.exe', '/C', tempbat])
204+
assert result == 0, format("Не удалось разобрать\
205+
обработку %s" % (fullpathfile))
203206
if not result == 0:
204207
logging.error(format("Не удалось разобрать \
205208
обработку %s" % (fullpathfile)))
206-
raise format("Не удалось разобрать обработку %s" %(fullpathfile))
209+
raise format("Не удалось разобрать\
210+
обработку %s" % (fullpathfile))
207211
returnlist.append(newsourcepath)
208212
logging.info("Разобран в %s" % (newsourcepath))
209213

@@ -219,10 +223,10 @@ def add_to_git(pathlists):
219223

220224
def compile(input, output, ext):
221225
import codecs
222-
if input is None:
223-
raise "Не указан путь к входящему каталогу"
224-
if output is None:
225-
raise "Не указан путь к исходящему файлу"
226+
227+
assert not input is None, "Не указан путь к входящему каталогу"
228+
assert not output is None, "Не указан путь к исходящему файлу"
229+
226230
extfile = "epf" if ext == "auto" else ext
227231

228232
dirsource = os.path.abspath(os.path.join(os.path.curdir, input))
@@ -238,33 +242,48 @@ def compile(input, output, ext):
238242
lines = r.read()
239243
lines = lines.split('\r\n')
240244
for l in lines:
245+
if l.startswith(u'\ufeff'):
246+
l = l[1:]
241247
list = l.split("-->")
242248
if len(list) < 2:
243249
continue
244-
log.error(l)
250+
log.debug(l)
245251
newPath = os.path.join(tempPath, list[0])
246252
dirname = os.path.dirname(newPath)
247253
if not os.path.exists(dirname):
248254
os.mkdir(dirname)
249-
oldPath = os.path.join(dirsource, list[1].replace("\\", os.path.sep))
255+
oldPath = os.path.join(dirsource,
256+
list[1].replace(
257+
"\\", os.path.sep)
258+
)
259+
250260
if os.path.isdir(oldPath):
251261
#tempFile = tempfile.mkstemp()
252262
newPath = os.path.join(tempPath, list[0])
253263
shutil.copytree(oldPath, newPath)
254264
else:
255-
log.error(oldPath)
265+
log.debug(oldPath)
256266
shutil.copy(
257267
os.path.normpath(oldPath),
258268
newPath
259269
)
260270

261271
#вызовем v8unpack, для сборки файла из исходников.
262272
tempFile = tempfile.mktemp("."+extfile)
263-
log.debug(["UnpackV8.exe", "-PACK", '{}{}'.format(tempPath, os.path.sep), tempFile])
264-
log.error('UnpackV8.exe -B "{}" "{}"'.format('{}{}'.format(tempPath, os.path.sep), tempFile))
265-
result = subprocess.check_call(['UnpackV8.exe', '-PACK', '{}{}'.format(tempPath, os.path.sep), tempFile])
273+
log.debug('unpackv8 -B "{}" "{}"'.format('{}'.format(tempPath), tempFile))
274+
result = subprocess.check_call(
275+
['unpackv8',
276+
'-B',
277+
'{}'.format(tempPath),
278+
tempFile]
279+
)
280+
281+
log.debug("copy from {} to {}".format(tempFile, output))
282+
assert result == 0, "Не удалось упаковать каталог {}".format(tempPath)
266283
shutil.move(tempFile, output)
267284

285+
return output
286+
268287
def main():
269288

270289
parser = argparse.ArgumentParser(description="Утилита \

tests/test_compile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import unittest
2+
import pyv8unpack
3+
from os import path as path
4+
import tempfile
5+
6+
7+
class TestV8Unpack(unittest.TestCase):
8+
9+
def test_compile_from_source(self):
10+
11+
tpath = tempfile.mkdtemp()
12+
file = path.join(path.curdir, "tests", "Fixture.epf")
13+
assert pyv8unpack.decompile([file], tpath)
14+
tpath = path.join(tpath, "tests", "Fixture")
15+
filenew = tempfile.mktemp()
16+
assert pyv8unpack.compile(tpath, filenew, "epf") == filenew
17+
18+
def test_decompile(self):
19+
20+
tpath = tempfile.mkdtemp()
21+
file = path.join(path.curdir, "tests", "Fixture.epf")
22+
assert pyv8unpack.decompile([file], tpath)

0 commit comments

Comments
 (0)