forked from gurnec/btcrecover
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-unicode.py
105 lines (83 loc) · 4.03 KB
/
make-unicode.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
#!/usr/bin/python
# make-unicode.py -- build the Unicode version of btcrecover from the ASCII version
# Copyright (C) 2014 Christopher Gurnee
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License version 2 for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# If you find this program helpful, please consider a small
# donation to the developer at the following Bitcoin address:
#
# 17LGpN2z62zp7RS825jXwYtE7zZ19Mxxu8
#
# Thank You!
from __future__ import print_function
import os.path as path
install_dir = path.dirname(__file__)
# This is a bit fragile, but it's probably good enough. It simply looks
# for certain strings, and comments or uncomments code between them.
def make_unicode_version(ascii_name, unicode_name):
ascii_version_path = path.join(install_dir, ascii_name)
unicode_version_path = path.join(install_dir, unicode_name)
if not path.isfile(ascii_version_path):
exit("can't find " + ascii_version_path)
if path.isfile (unicode_version_path) and \
path.getmtime(unicode_version_path) >= path.getmtime(ascii_version_path):
print("existing Unicode version "+unicode_name+" is up-to-date")
return False
print("making "+unicode_name)
with open(ascii_version_path, "rb") as ascii_version:
with open(unicode_version_path, "wb") as unicode_version:
# Search for the first "key" string
for line in ascii_version:
unicode_version.write(line)
if line.startswith("# Uncomment for Unicode support"):
break
# Uncomment the block of code up until the next "key" string
for line in ascii_version:
if line.startswith("# Uncomment for ASCII-only support"):
unicode_version.write(line)
break
unicode_version.write(line[1:] if line.startswith("#") else line)
# Comment out the next block of code up until the first empty line
for line in ascii_version:
if line.strip() == "":
unicode_version.write(line)
break
unicode_version.write("#")
unicode_version.write(line)
# Copy the rest of the file
for line in ascii_version:
unicode_version.write(line)
return True
if __name__ == '__main__':
import argparse, atexit, unittest
parser = argparse.ArgumentParser()
parser.add_argument("--no-quicktests", action="store_true", help="don't run the QuickTests suite")
parser.add_argument("--no-pause", action="store_true", help="don't prompt 'Press Enter to exit'")
args = parser.parse_args()
# By default, pause before exiting
if not args.no_pause:
atexit.register(lambda: raw_input("\nPress Enter to exit ..."))
# Build the Unicode versions of btcrecover and the test-btcr test suite
modified1 = make_unicode_version("btcrecover.py", "btcrecoveru.py")
modified2 = make_unicode_version("test-btcr.py", "test-btcru.py")
if not modified1 and not modified2:
print("nothing left to do, exiting")
# If at least one of the files were updated, by default run the QuickTests suite
elif not args.no_quicktests:
print("\nRunning quick tests\n")
test_btcr = __import__("test-btcru")
if unittest.TextTestRunner(buffer=True).run(test_btcr.QuickTests()).wasSuccessful():
print("\nStart test-btcru.py to run the full test suite.")
else:
exit(1)