Skip to content

Commit e52ca22

Browse files
committed
I04_1-168: program can be launched with config file as argument
1 parent 3641e03 commit e52ca22

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test-output
55
demo-resources
66
*.pyc
77
config.ini
8+
launch_barcode.bat
89

910
build
1011
dist

build.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ pyinstaller --onefile --windowed main.py
88
move dist\main.exe ..\bin\barcode.exe
99
rd /S /Q build
1010
rd /S /Q dist
11-
del main.spec
11+
del main.spec
12+
13+
@echo start barcode.exe --config_file .\config.ini>"..\bin\launch_barcode.bat"

dls_barcode/main.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010
from PyQt4 import QtGui
1111
from gui import DiamondBarcodeMainWindow
12+
import argparse
1213

1314
# Detect if the program is running from source or has been bundled
1415
IS_BUNDLED = getattr(sys, 'frozen', False)
1516
if IS_BUNDLED:
16-
CONFIG_FILE = "./config.ini"
17+
DEFAULT_CONFIG_FILE = "./config.ini"
1718
else:
18-
CONFIG_FILE = "../config.ini"
19+
DEFAULT_CONFIG_FILE = "../config.ini"
1920

2021

21-
def main():
22+
def main(config_file):
2223
app = QtGui.QApplication(sys.argv)
23-
ex = DiamondBarcodeMainWindow(CONFIG_FILE)
24+
ex = DiamondBarcodeMainWindow(config_file)
2425
sys.exit(app.exec_())
2526

2627

@@ -30,4 +31,10 @@ def main():
3031
import multiprocessing
3132
multiprocessing.freeze_support()
3233

33-
main()
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("-cf", "--config_file", type=str, default=DEFAULT_CONFIG_FILE,
36+
help="The path of the configuration file (default=" + DEFAULT_CONFIG_FILE + ")")
37+
args = parser.parse_args()
38+
print("CONFIG: " + args.config_file)
39+
40+
main(args.config_file)

tests/system_tests/system_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
CONFIG_FILE = "../config.ini"
3838
# TODO: restore the four commented lines below
39-
# OPTIONS = BarcodeConfig(CONFIG_FILE)
39+
# OPTIONS = BarcodeConfig(DEFAULT_CONFIG_FILE)
4040

4141
# STORE = Store(OPTIONS.store_directory.value(), OPTIONS)
4242

0 commit comments

Comments
 (0)