-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSFyPy.py
198 lines (150 loc) · 7.38 KB
/
SFyPy.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
###############################################################################
# #
# SFyPy Salesforce Python dataLoader #
# #
###############################################################################
import os
from tkinter import *
import tkinter.scrolledtext as tkscrolled
import tkinter.messagebox as tkMessageBox
import Job
settingsPath = os.getcwd() + "\settings.txt"
arrAction = ['upsert','insert','update']
with open(settingsPath, "r") as f:
settings = f.read()
txtRecordType, optionAction, txtServerName, txtDatabaseName, txtServerUsername, txtServerPassword, txtSfUsername, txtSfPassword, txtSfSecurityToken, txtUseSfSandbox, txtBatchSize, txtSFInstance = settings.split('|')
def main():
root = Tk()
root.title('SFyPy')
root.resizable(width=False, height=False)
render(root)
def btnGenerate_Clicked():
try:
queryResult = Job.executeQuery(str(eQuery.get(1.0, END)), str(eRecordType.get()))
tkMessageBox.showinfo("Finished", queryResult)
except Exception as e:
tkMessageBox.showinfo("Error", e)
def btnSave_Clicked():
try:
with open(settingsPath, 'w') as f:
f.write(eRecordType.get() + "|" + strVarAction.get() + "|" + eServerName.get() + "|" + eDatabaseName.get() + "|" + eServerUsername.get() + "|" + eServerPassword.get() + "|" + eSfUsername.get() + "|" + eSfPassword.get() + "|" + eSfSecurityToken.get() + "|" + str(vUseSfSandbox.get()) + "|" + eBatchSize.get() + "|" + eSFInstance.get())
tkMessageBox.showinfo("Saved", "Your settings have been saved.")
except Exception as e:
tkMessageBox.showinfo("Error", e)
def btnRunAll_Clicked():
try:
result = Job.main()
tkMessageBox.showinfo("Finished", result)
except Exception as e:
tkMessageBox.showinfo("Error", str(e))
def btnRun_Clicked():
try:
if(str(eRecordType.get()) == ""):
tkMessageBox.showinfo("Error", "Enter an object to update")
return
Job.executeQuery(str(eQuery.get(1.0, END)), str(eRecordType.get()))
rows = Job.readCSV(str(eRecordType.get()))
result = Job.uploadResultsToSalesforce(str(eRecordType.get()), str(strVarAction.get()), rows, str(eSfUsername.get()), str(eSfPassword.get()), str(eSfSecurityToken.get()), str(vUseSfSandbox.get()))
tkMessageBox.showinfo("Finished", result)
except Exception as e:
tkMessageBox.showinfo("Error", str(e))
def render(root):
try:
queryPath = os.getcwd() + "\\queries\\" + txtRecordType + ".txt"
with open(queryPath, "r") as f:
global txtQuery
txtQuery = f.read()
except Exception as e:
txtQuery = ""
lblSfUsername = Label(root, text="Salesforce Username")
lblSfUsername.grid(row=1, column=0)
global eSfUsername
vSfUsername = StringVar(root, value=txtSfUsername)
eSfUsername = Entry(root, textvariable=vSfUsername, width=130)
eSfUsername.grid(row=1, column=1)
lblSfPassword = Label(root, text="Salesforce Password")
lblSfPassword.grid(row=2, column=0)
global eSfPassword
vSfPassword = StringVar(root, value=txtSfPassword)
eSfPassword = Entry(root, show="*", textvariable=vSfPassword, width=130)
eSfPassword.grid(row=2, column=1)
lblSfSecurityToken = Label(root, text="Salesforce Security Token")
lblSfSecurityToken.grid(row=3, column=0)
global eSfSecurityToken
vSfSecurityToken = StringVar(root, value=txtSfSecurityToken)
eSfSecurityToken = Entry(root, show="*", textvariable=vSfSecurityToken, width=130)
eSfSecurityToken.grid(row=3, column=1)
global vUseSfSandbox
vUseSfSandbox = IntVar(root, value=txtUseSfSandbox)
chkUseSfSandbox = Checkbutton(root, text="Use Salesforce Sandbox", variable=vUseSfSandbox)
chkUseSfSandbox.grid(row=4, column=0)
lblRecordType = Label(root, text="Object")
lblRecordType.grid(row=5, column=0)
global eRecordType
vRecordType = StringVar(root, value=txtRecordType)
eRecordType = Entry(root, textvariable=vRecordType)
eRecordType.grid(row=5, column=1)
lblAction = Label(root, text="Action")
lblAction.grid(row=6, column=0)
global strVarAction
strVarAction = StringVar()
strVarAction.set(optionAction)
omAction = OptionMenu(root,strVarAction,*arrAction)
omAction.grid(row=6, column=1)
lblQuery = Label(root, text="Query")
lblQuery.grid(row=7, column=0)
global eQuery
eQuery = tkscrolled.ScrolledText(root, height=20, width=100)
eQuery.insert(INSERT, txtQuery)
eQuery.grid(row=7, column=1)
lblServerName = Label(root, text="Server Name")
lblServerName.grid(row=8, column=0)
global eServerName
vServerName = StringVar(root, value=txtServerName)
eServerName = Entry(root, textvariable=vServerName, width=130)
eServerName.grid(row=8, column=1)
lblDatabaseName = Label(root, text="Database Name")
lblDatabaseName.grid(row=9, column=0)
global eDatabaseName
vDatabaseName = StringVar(root, value=txtDatabaseName)
eDatabaseName = Entry(root, textvariable=vDatabaseName, width=130)
eDatabaseName.grid(row=9, column=1)
lblServerUsername = Label(root, text="Server Username")
lblServerUsername.grid(row=10, column=0)
global eServerUsername
vServerUsername = StringVar(root, value=txtServerUsername)
eServerUsername = Entry(root, textvariable=vServerUsername, width=130)
eServerUsername.grid(row=10, column=1)
lblServerPassword = Label(root, text="Server Password")
lblServerPassword.grid(row=11, column=0)
global eServerPassword
vServerPassword = StringVar(root, value=txtServerPassword)
eServerPassword = Entry(root, show="*", textvariable=vServerPassword, width=130)
eServerPassword.grid(row=11, column=1)
lblBatchSize = Label(root, text="Batch Size")
lblBatchSize.grid(row=12, column=0)
global eBatchSize
vBatchSize = StringVar(root, value=txtBatchSize)
eBatchSize = Entry(root, textvariable=vBatchSize, width=130)
eBatchSize.grid(row=12, column=1)
lblSFInstance = Label(root, text="Salesforce Instance")
lblSFInstance.grid(row=13, column=0)
global eSFInstance
vSFInstance = StringVar(root, value=txtSFInstance)
eSFInstance = Entry(root, textvariable=vSFInstance, width=130)
eSFInstance.grid(row=13, column=1)
lblHidden = Label(root)
lblHidden.grid(row=14, column=0)
btnSave = Button(root, text="Save Settings", command=btnSave_Clicked)
btnSave.grid(row=15, column=0)
btnRun = Button(root, text="Upload Query", command=btnRun_Clicked)
btnRun.grid(row=15, column=2)
btnRunAll = Button(root, text="Upload all CSVs", command=btnRunAll_Clicked)
btnRunAll.grid(row=15, column=3)
btnGenerate = Button(root, text="Generate Test File", command=btnGenerate_Clicked)
btnGenerate.grid(row=15, column=1)
lblHidden = Label(root)
lblHidden.grid(row=16, column=0)
root.update()
root.mainloop()
main()