|
8 | 8 |
|
9 | 9 | HOME_DIRECTORY=os.path.expanduser('~')
|
10 | 10 | LISICA_DIRECTORY=os.path.join(HOME_DIRECTORY,".lisicagui")
|
11 |
| -licenseFile = os.path.join(HOME_DIRECTORY,".insilab-license.txt") |
12 |
| -iconFolder=os.path.join(LISICA_DIRECTORY,"Icons") |
| 11 | +versionFile = os.path.join(LISICA_DIRECTORY,"version.txt") |
13 | 12 |
|
14 |
| -class Activation: |
15 |
| - def __init__(self,exe_path): |
16 |
| - |
17 |
| - self.Window=Tk() |
18 |
| - #self.Window.config(background="white") |
19 |
| - self.Window.geometry('{}x{}'.format(620,250)) |
20 |
| - self.Window.title("Product Activation") |
21 |
| - self.VALID=False |
22 |
| - self.exe_path=exe_path |
23 |
| - print self.exe_path |
24 |
| - self.initGUI() |
25 |
| - |
26 |
| - |
27 |
| - |
28 |
| - def initGUI(self): |
29 |
| - |
30 |
| - photo=PhotoImage(master=self.Window,file=os.path.join(iconFolder,"lisica_icon.gif")) |
31 |
| - self.display=Label(self.Window,image=photo) |
32 |
| - self.display.image=photo |
33 |
| - self.display.grid(row=0,column=0,rowspan=2) |
34 |
| - |
35 |
| - self.activation_Status=StringVar(master=self.Window) |
36 |
| - self._Website=StringVar(master=self.Window) |
37 |
| - |
38 |
| - self.key_Frame=LabelFrame(self.Window,text="Enter Activation Key",labelanchor="nw",font=("Times", 13),relief="ridge",borderwidth=4) |
39 |
| - self.key_Frame.grid(row=0,column=1,sticky=W+E,padx=(10,10),pady=(40,10)) |
40 |
| - self.key_Entry=Entry(self.key_Frame,width=30,borderwidth=3,font=("Courier",12)) |
41 |
| - self.activate_Button=Button(self.key_Frame,text="Activate",font=("Times", 11),command=self.activate) |
42 |
| - self.key_Entry.grid(row=2,padx=(5,1),pady=(20,10),sticky=E) |
43 |
| - self.activate_Button.grid(row=2,column=2,sticky=W,pady=(20,10),padx=(1,5)) |
44 |
| - |
45 |
| - |
46 |
| - self.activation_Status.set( |
47 |
| -"""*Activating LiSiCA requires a license. |
48 |
| - To obtain a valid license key contact us at [email protected].""" |
49 |
| - ) |
50 |
| - self.info_msg=Label(self.key_Frame,textvariable=self.activation_Status,font=("Times", 11)) |
51 |
| - self.info_msg.grid(row=4,columnspan=2,padx=(2,2),pady=(20,2),sticky=W+S) |
52 |
| - |
53 |
| - self.website=Label(self.Window,text="For more information, please visit our website: http://www.insilab.com",font=("Times",11)) |
54 |
| - self.website.grid(row=2,columnspan=2,padx=(5,5),pady=(10,1)) |
55 |
| - #Label(self.Window,text=""" Please feel free to visit our website at http://www.insilab.com.""").grid(row=5,padx=(5,5),sticky=W+S) |
56 |
| - |
57 |
| - self.Window.mainloop() |
58 |
| - |
59 |
| - def activate(self): |
60 |
| - |
61 |
| - |
62 |
| - self.startupinfo=None |
63 |
| - if os.name=='nt': |
64 |
| - try: |
65 |
| - self.startupinfo=subprocess.STARTUPINFO() |
66 |
| - self.startupinfo.dwFlags|=subprocess.STARTF_USESHOWWINDOW |
67 |
| - except: |
68 |
| - self.startupinfo.dwFlags|=subprocess._subprocess.STARTF_USESHOWWINDOW |
69 |
| - |
70 |
| - license_code=self.key_Entry.get() |
71 |
| - print "license_code = ", license_code |
72 |
| - #~ activate_Command=self.exe_path+" --activate "+license_code+" --plugin" |
73 |
| - activate_Command=[self.exe_path, "--activate", license_code, "--plugin"] |
74 |
| - print "activate_Command = ", activate_Command |
75 |
| - try: |
76 |
| - os.chdir( LISICA_DIRECTORY ) |
77 |
| - proc = subprocess.Popen(activate_Command,shell=False,startupinfo=self.startupinfo) |
78 |
| - while proc.poll() is None: |
79 |
| - self.Window.update() |
80 |
| - exitCode=proc.returncode |
81 |
| - print exitCode |
82 |
| - if exitCode == 0: |
83 |
| - self.VALID=True |
84 |
| - #tkMessageBox.showinfo("License", "License validation succeeded. LiSiCA plugin is activated") |
85 |
| - self.key_Frame.destroy() |
86 |
| - |
87 |
| - |
88 |
| - self.actiavted_Frame=LabelFrame(self.Window,relief="ridge",borderwidth=4) |
89 |
| - self.actiavted_Frame.grid(row=0,column=1,sticky=W+E,padx=(10,10),pady=(40,10)) |
90 |
| - self.activated_Label=Label(self.actiavted_Frame,font=("Times",11),text="License validation succeeded. LiSiCA plugin is activated") |
91 |
| - self.activated_Label.grid(row=2,padx=(5,1),pady=(20,10),columnspan=2,sticky=E) |
92 |
| - self.run=BooleanVar(master=self.Window) |
93 |
| - self.run.set(True) |
94 |
| - self.run_plugin=Radiobutton(self.actiavted_Frame,text="Start LiSiCA plugin now", variable=self.run, command=self.finish) |
95 |
| - |
96 |
| - self.finish_Button=Button(self.actiavted_Frame,text="Run LiSiCA",font=("Times", 11),command=self.finish) |
97 |
| - self.finish_Button.grid(row=3,column=2,sticky=W,pady=(20,10),padx=(1,5)) |
98 |
| - |
99 |
| - |
100 |
| - |
101 |
| - |
102 |
| - |
103 |
| - |
104 |
| - elif exitCode == 200: |
105 |
| - self.VALID=True |
106 |
| - #tkMessageBox.showinfo("License","There is a new version of LiSiCA plugin available. For information on this update please visit our website: http://www.insilab.com.") |
107 |
| - self.key_Frame.destroy() |
108 |
| - |
109 |
| - |
110 |
| - |
111 |
| - |
112 |
| - elif exitCode == 201: |
113 |
| - self.key_Entry.delete(0, END) |
114 |
| - self.activation_Status.set( |
115 |
| -"""*Invalid License Code. |
116 |
| - Please contact us at [email protected] to obtain a valid license key.""" |
117 |
| - ) |
118 |
| - self.info_msg.configure(fg="red") |
119 |
| - #tkMessageBox.showerror("License Error","Invalid license code. Please contact us at [email protected] to obtain a valid license key.") |
120 |
| - |
121 |
| - |
122 |
| - elif exitCode == 202: |
123 |
| - self.key_Entry.delete(0, END) |
124 |
| - self.activation_Status.set( |
125 |
| -"""*There is another computer activated by this license. |
126 |
| - Please contact us at [email protected] for detailed information.""" |
127 |
| - ) |
128 |
| - self.info_msg.configure(fg="red") |
129 |
| - #tkMessageBox.showerror("License Error","There is another computer activated by this license. Please contact us at [email protected] for detailed information.") |
130 |
| - |
131 |
| - |
132 |
| - elif exitCode == 203: |
133 |
| - self.key_Entry.delete(0, END) |
134 |
| - self.activation_Status.set( |
135 |
| -"""*Error getting info about computer. |
136 |
| - Please contact us at [email protected] for detailed information.""" |
137 |
| - ) |
138 |
| - self.info_msg.configure(fg="red") |
139 |
| - #tkMessageBox.showerror("License Error","Error getting info about computer. Please contact us at [email protected] for detailed information.") |
140 |
| - |
141 |
| - |
142 |
| - elif exitCode == 204: |
143 |
| - self.key_Entry.delete(0, END) |
144 |
| - self.activation_Status.set( |
145 |
| -"""*Please check your internet connection or try again later. |
146 |
| - Please contact us at [email protected] for detailed information.""" |
147 |
| - ) |
148 |
| - self.info_msg.configure(fg="red") |
149 |
| - #tkMessageBox.showerror("License Error","Please check your internet connection or try again later. Feel free to contact us at [email protected] for detailed information.") |
150 |
| - |
151 |
| - |
152 |
| - except subprocess.CalledProcessError as licenseStatus: |
153 |
| - self.key_Entry.delete(0, END) |
154 |
| - tkMessageBox.showerror('License Error', licenseStatus.output) |
155 |
| - |
156 |
| - def finish(self): |
157 |
| - import Plugin_GUI |
158 |
| - Plugin_GUI.main() |
159 |
| - |
160 |
| - |
161 |
| - |
162 |
| - |
163 |
| - |
164 |
| - |
165 |
| - |
166 |
| - |
167 |
| - |
168 |
| -def activate(exe_path): |
169 |
| - |
170 |
| - a=Activation(exe_path) |
171 |
| - if a.VALID==True: |
172 |
| - if a.run.get()==True: |
173 |
| - print "1" |
174 |
| - return 1 |
175 |
| - else: |
176 |
| - print "2" |
177 |
| - return 2 |
178 |
| - else: |
179 |
| - print "0" |
180 |
| - return 0 |
181 |
| - |
182 |
| - #a.Window.protocol('WM_DELETE_WINDOW',a.finish) |
183 |
| - |
| 13 | +def writeToInsilabTxt(latestVersion): |
| 14 | + # needed for backward compatibility |
| 15 | + pass |
184 | 16 |
|
185 | 17 | def checkLicenseStatus():
|
186 |
| - lisica_line=() |
187 |
| - if os.path.isfile(licenseFile): |
188 |
| - with open(licenseFile) as lFile: |
189 |
| - for line in lFile: |
190 |
| - |
191 |
| - if line[:7] == "lisica ": |
192 |
| - lisica_line=line.split() |
193 |
| - license_details={'Key':lisica_line[1],'Version':lisica_line[2]} |
194 |
| - |
195 |
| - |
196 |
| - return license_details |
197 |
| - return None |
| 18 | + # needed for backward compatibility |
| 19 | + return {'Key':"FREE_FOR_ACADEMIC_USE",'Version':"1.0.0"} |
198 | 20 |
|
199 | 21 | def checkVersionGUI():
|
200 |
| - lisica_line=() |
201 |
| - if os.path.isfile(licenseFile): |
202 |
| - with open(licenseFile) as lFile: |
203 |
| - for line in lFile: |
204 |
| - |
205 |
| - if line[:9] == "lisicagui": |
206 |
| - lisica_line=line.split() |
207 |
| - license_details={'Key':lisica_line[1],'Version':lisica_line[2]} |
208 |
| - |
209 |
| - |
210 |
| - return license_details |
211 |
| - |
212 |
| - return None |
| 22 | + if os.path.isfile(versionFile): |
| 23 | + with open(versionFile) as vFile: |
| 24 | + lines = vFile.readlines() |
| 25 | + return {'Key':"FREE_FOR_ACADEMIC_USE",'Version':lines[0].strip()} |
| 26 | + return None |
213 | 27 |
|
214 |
| -def writeToInsilabTxt(latestVersion): |
215 |
| - #get the current version from version.txt? version url |
216 |
| - #call this only one inside installation(?) |
217 |
| - |
218 |
| - if os.path.isfile(licenseFile): |
219 |
| - with open(licenseFile) as insilabFile: |
220 |
| - lines=insilabFile.readlines() |
221 |
| - InsilabFile=open(licenseFile,"w") |
222 |
| - for line in lines: |
223 |
| - if line[:9]=="lisicagui": |
224 |
| - pass |
225 |
| - else: |
226 |
| - InsilabFile.write(line) |
227 |
| - else: |
228 |
| - InsilabFile=open(licenseFile,"w") |
229 |
| - InsilabFile.write("lisicagui freelicense " + latestVersion +"\n") |
230 |
| - |
231 |
| - |
232 |
| - |
233 |
| - |
234 |
| - |
235 |
| - |
236 |
| - |
237 |
| -if __name__ == "__main__": |
238 |
| - #For testing |
239 |
| - active=activate("so") |
240 |
| - |
241 | 28 |
|
242 |
| - |
0 commit comments