-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupwizard.py
124 lines (102 loc) · 4 KB
/
setupwizard.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import yaml
from PySide6.QtWidgets import QWizard, QWizardPage
from appinfo import Info
from path import Pathinfo
from wizardpage1 import Ui_WizardPage1
from wizardpage2 import Ui_WizardPage2
class SetupWizardPage2Data:
appid = None
certid = None
devid = None
token = None
class SetupWizardPage1(QWizardPage, Ui_WizardPage1):
def __init__(self):
super(SetupWizardPage1, self).__init__()
self.setupUi(self)
class SetupWizardPage2(QWizardPage, Ui_WizardPage2):
def __init__(self):
super(SetupWizardPage2, self).__init__()
self.pathinfo = Pathinfo()
self.setupUi(self)
self.registerField('production_appid*', self.lineEditAppid)
self.registerField('production_certid*', self.lineEditCertid)
self.registerField('production_devid*', self.lineEditDevid)
self.registerField('production_token*', self.lineEditToken)
def initializePage(self):
if os.path.exists(self.pathinfo.ebay):
with open(self.pathinfo.ebay, "r") as fd:
config = yaml.load(fd, Loader=yaml.SafeLoader)
self.lineEditAppid.setText(config['api.ebay.com']['appid'])
self.lineEditCertid.setText(config['api.ebay.com']['certid'])
self.lineEditDevid.setText(config['api.ebay.com']['devid'])
self.lineEditToken.setText(config['api.ebay.com']['token'])
self.completeChanged.emit()
def isComplete(self):
if len(self.lineEditAppid.text()) > 0 and len(self.lineEditCertid.text()) > 0 and len(self.lineEditDevid.text()) > 0 and len(self.lineEditToken.text()) > 0:
return True
return False
class SetupWizard(QWizard):
def __init__(self, parent=None, stopConnection = False):
self.window = parent
self.stopConnection = stopConnection
super(SetupWizard, self).__init__(parent)
self.pathinfo = Pathinfo()
self.dataPage2 = SetupWizardPage2Data()
page1 = SetupWizardPage1()
self.addPage(page1)
page2 = SetupWizardPage2()
self.addPage(page2)
def accept(self):
self.dataPage2.appid = self.field('production_appid')
self.dataPage2.certid = self.field('production_certid')
self.dataPage2.devid = self.field('production_devid')
self.dataPage2.token = self.field('production_token')
if self.generateEbayYaml():
if self.window is not None:
if os.path.exists(self.pathinfo.ebay):
self.window.button_start.setDisabled(False)
else:
self.window.button_start.setDisabled(True)
self.window.show()
self.hide()
return True
if os.path.exists(self.pathinfo.ebay):
self.window.button_start.setDisabled(False)
else:
self.window.button_start.setDisabled(True)
return False
def generateEbayYaml(self):
ebayYaml = {
'name': 'ebay_api_config',
'api.sandbox.ebay.com': {
'compatability': '719',
'appid': '',
'certid': '',
'devid': '',
'token': '',
},
'api.ebay.com': {
'compatability': '719',
'appid': self.dataPage2.appid,
'certid': self.dataPage2.certid,
'devid': self.dataPage2.devid,
'token': self.dataPage2.token,
},
'svcs.ebay.com': {
'appid': self.dataPage2.appid,
},
'open.api.ebay.com': {
'appid': self.dataPage2.appid,
},
}
# stop connection
if self.stopConnection and os.path.exists(self.pathinfo.ebay):
self.window.stop()
ebayYamlPath = self.pathinfo.ebay
try:
with open(ebayYamlPath, 'w') as fd:
yaml.dump(ebayYaml, fd)
except:
return False
return True