Skip to content

Commit 2d54222

Browse files
committed
save config files and logs to user datadir
1 parent 141af5e commit 2d54222

File tree

9 files changed

+33
-36
lines changed

9 files changed

+33
-36
lines changed

.settings/org.eclipse.core.resources.prefs

Lines changed: 0 additions & 12 deletions
This file was deleted.

pet4l.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
import sys
4-
import os.path
4+
import os
55
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
66
from PyQt5.QtWidgets import QApplication
77
from PyQt5.Qt import Qt, QPixmap, QSplashScreen, QProgressBar, QColor, QPalette, QLabel
@@ -11,14 +11,14 @@
1111
if __name__ == '__main__':
1212
# Create App
1313
app = QApplication(sys.argv)
14+
1415
if getattr( sys, 'frozen', False ) :
1516
# running in a bundle
1617
imgDir = os.path.join(sys._MEIPASS, 'img')
17-
#log_File = os.path.join(sys._MEIPASS, 'img')
18-
else :
18+
19+
else:
1920
# running live
20-
imgDir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'img')
21-
#log_File = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lastLogs.html')
21+
imgDir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'img')
2222

2323
### --------------
2424

specPet4l.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ with open(os.path.join(base_dir, 'src', 'version.txt')) as version_file:
1515
version_file.close()
1616
version_str = version_data["number"] + version_data["tag"]
1717

18-
add_files = [('src/rpcServer.json', '.'), ('src/version.txt', '.'), ('img', 'img')]
18+
add_files = [('src/version.txt', '.'), ('img', 'img')]
1919

2020
lib_path = next(p for p in sys.path if 'site-packages' in p)
2121
if os_type == 'win32':

src/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import os.path
55

6+
APPDATA_DIRNAME = ".PET4L-DATA"
67
MPATH = "44'/77'/"
78
WIF_PREFIX = 212 # 212 = d4
89
MAGIC_BYTE = 30
@@ -12,4 +13,6 @@
1213
MINIMUM_FEE = 0.0001 # minimum PIV/kB
1314
starting_width = 1033
1415
starting_height = 785
15-
log_File = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lastLogs.html')
16+
home_dir = os.path.expanduser('~')
17+
user_dir = os.path.join(home_dir, APPDATA_DIRNAME)
18+
log_File = os.path.join(user_dir, 'lastLogs.html')

src/mainApp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
66
import signal
77
from misc import getVersion, printDbg
8-
from constants import starting_height, starting_width
8+
from constants import starting_height, starting_width, user_dir
99
from PyQt5.Qt import QMainWindow, QIcon, QAction
1010
from mainWindow import MainWindow
1111
from qt.dlg_configureRPCserver import ConfigureRPCserver_dlg
@@ -34,6 +34,9 @@ def __init__(self, imgDir):
3434
# Get version and title
3535
self.version = getVersion()
3636
self.title = 'PET4L - PIVX Emergency Tool For Ledger - v.%s-%s' % (self.version['number'], self.version['tag'])
37+
# Create the userdir if it doesn't exist
38+
if not os.path.exists(user_dir):
39+
os.makedirs(user_dir)
3740
# Initialize user interface
3841
self.initUI(imgDir)
3942

src/mainWindow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def __init__(self, parent, imgDir):
5454
###-- Create Queues and redirect stdout and stderr (eventually)
5555
self.queue = Queue()
5656
self.queue2 = Queue()
57-
sys.stdout = WriteStream(self.queue)
58-
sys.stderr = WriteStream(self.queue2)
57+
#sys.stdout = WriteStream(self.queue)
58+
#sys.stderr = WriteStream(self.queue2)
5959

6060
###-- Init last logs
6161
logFile = open(log_File, 'w+')

src/misc.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88
from PyQt5.QtCore import QObject, pyqtSignal
99

10-
from constants import log_File
10+
from constants import log_File, user_dir
1111

1212
def append_to_logfile(text):
1313
try:
@@ -148,14 +148,18 @@ def splitString(text, n):
148148
def readRPCfile():
149149
try:
150150
import simplejson as json
151-
config_file = os.path.join(
152-
os.path.dirname(os.path.abspath(__file__)), 'rpcServer.json')
153-
with open(config_file) as data_file:
154-
rpc_config = json.load(data_file)
155-
data_file.close()
151+
config_file = os.path.join(user_dir, 'rpcServer.json')
152+
if os.path.exists(config_file):
153+
with open(config_file) as data_file:
154+
rpc_config = json.load(data_file)
155+
data_file.close()
156+
else:
157+
raise Exception("No rpcServer.json found. Creating new.")
156158
except Exception as e:
157-
printException(getCallerName(), getFunctionName(), "error reading RPC file", e.args)
158-
return "127.0.0.1", "45458", "default_user", "default_pass"
159+
# save default config and return it
160+
config = {"rpc_ip": "127.0.0.1", "rpc_port": 45458, "rpc_user": "myUsername", "rpc_password": "myPassword"}
161+
writeRPCfile(config)
162+
return "127.0.0.1", 45458, "myUsername", "myPassword"
159163

160164
rpc_ip = rpc_config.get('rpc_ip')
161165
rpc_port = int(rpc_config.get('rpc_port'))
@@ -182,11 +186,11 @@ def sec_to_time(seconds):
182186
def writeRPCfile(configuration):
183187
try:
184188
import simplejson as json
185-
rpc_file = os.path.join(
186-
os.path.dirname(os.path.abspath(__file__)), 'rpcServer.json')
189+
rpc_file = os.path.join(user_dir, 'rpcServer.json')
187190
with open(rpc_file, 'w+') as data_file:
188191
json.dump(configuration, data_file)
189192
data_file.close()
193+
190194
except Exception as e:
191195
printException(getCallerName(), getFunctionName(), "error writing RPC file", e.args)
192196

src/qt/dlg_configureRPCserver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ def __init__(self, main_wnd):
2323

2424
def initUI(self):
2525
self.ui = Ui_ConfigureRPCserverDlg()
26-
self.ui.setupUi(self)
26+
self.ui.setupUi(self, self.main_wnd)
2727

2828

2929
def loadRPCfile(self):
30-
self.rpc_ip, self.rpc_port, self.rpc_user, self.rpc_password = readRPCfile()
30+
self.rpc_ip, self.rpc_port, self.rpc_user, self.rpc_password = readRPCfile()
3131

3232

3333

3434
class Ui_ConfigureRPCserverDlg(object):
35-
def setupUi(self, ConfigureRPCserverDlg):
35+
def setupUi(self, ConfigureRPCserverDlg, main_wnd):
3636
ConfigureRPCserverDlg.setModal(True)
3737
## -- Layout
3838
self.layout = QGroupBox(ConfigureRPCserverDlg)

src/rpcServer.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)