-
Notifications
You must be signed in to change notification settings - Fork 9
/
cmdc
executable file
·1978 lines (1671 loc) · 59.1 KB
/
cmdc
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python2
######################################################################
# Python imports
######################################################################
import pygtk
pygtk.require('2.0')
import gtk
import os
import platform
import sys
import time
import webbrowser
import subprocess
import vte
import re
import urllib
import urllib2
import ConfigParser
import commands
import zipfile
import shutil
import fileinput
from glob import glob
MAIN_VBOX = gtk.VBox(False, 0)
toptable = gtk.Table(1, 3, False)
tableB = gtk.Table(1, 2, False)
optFrame = gtk.Frame()
class Tools():
def processor(self):
count = 0
for line in open('/proc/cpuinfo', 'r'):
if line.startswith('processor'):
count += 1
return count
def UnzipFile(self, zipurl, myfile, mydir):
current = os.getcwd()
os.chdir(mydir)
urllib.urlretrieve(zipurl, myfile)
zfile = zipfile.ZipFile(myfile)
for name in zfile.namelist():
(dirname, filename) = os.path.split(name)
if not os.path.exists(dirname):
os.mkdir(dirname)
zfile.extract(name)
zfile.close()
os.remove(myfile)
os.chdir(current)
def custom_list_file(self, dirpath, filename):
RFILES = []
for path, dirs, files in os.walk(dirpath, followlinks=True):
if files:
for file in files:
p=os.path.join(path,file)
if os.path.isfile(p) and not os.path.islink(p):
p = p.split("/")
p = p[-1]
if p == filename:
RFILES.append(os.path.join(path,p))
if not RFILES:
return None
else:
return RFILES
def custom_list_dir(self, dirpath, dirname):
RDIRS = []
for path, dirs, files in os.walk(dirpath, followlinks=True):
if dirs:
for dir in dirs:
d = dir.split("/")
d = d[-1]
if d == dirname:
RDIRS.append(path)
if not RDIRS:
return None
else:
return RDIRS
def which(self, program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def grep(self, path, regex, which):
res = []
num = []
regObj = re.compile(regex)
for root, dirs, fnames in os.walk(path):
for fname in fnames:
if which == "File":
if regObj.match(fname):
res.append(os.path.join(root, fname))
else:
count = 0
try:
for line in open(os.path.join(root, fname), 'r'):
count += 1
if regex in line:
res.append(os.path.join(root, fname))
num.append(count)
except:
pass
if res and num:
return res, num
else:
return None
class Dialogs():
def CDial(self, dialog_type, title, message):
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type=dialog_type, buttons=gtk.BUTTONS_OK)
dialog.set_markup(title)
dialog.format_secondary_markup(message)
dialog.run()
dialog.destroy()
return True
def QDial(self, title, message):
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO)
dialog.set_markup(title)
dialog.format_secondary_markup(message)
response = dialog.run()
dialog.destroy()
if response == gtk.RESPONSE_YES:
return True
else:
return False
class Globals():
# Local config junk
myHOME = (os.environ['HOME'])
myGIT_CONF = ('%s/.gitconfig') % (myHOME)
myCONF_DIR = ('%s/.config/cmdc') % (myHOME)
myDATA_DIR = ('/usr/share/cmdc/')
myCONF = ('%s/cmdc.conf') % (myCONF_DIR)
myCONFIRM = ('%s/ask.confim') % (myCONF_DIR)
myREPO_CONF = ('%s/repo_list') % (myCONF_DIR)
myDEF_REPO_PATH = ('%s/build') % (myCONF_DIR)
AskConfirm = ('%s/ask.confim') % (myCONF_DIR)
# Resources
myMainTitle = ('CyanogenMod Dev Center')
myIMGS = ('%s/images') % (myDATA_DIR)
myTermWall = ('%s/termwall.jpg') % (myIMGS)
myTHEME = ('%s/theme/') % (myIMGS)
RunImg = ('%s/run.png') % (myIMGS)
DeviceImg = ('%s/device.png') % (myIMGS)
myRepoPatchFile = ('%s/cm-gerrit_patches') % (myCONF_DIR)
myCustDeviceFile = ('%s/cust_devices') % (myCONF_DIR)
aoscData = ('https://raw.github.com/lithid/CMDC_Data/master')
aoscDataProjects = ('%s/projects') % (aoscData)
myTermFont = ('Monospace 9')
# Strings
StrUserConfirm = '**** User Confirmation ****'
TargetOut = '%s/out/target/product/%s'
# Needed web urls
myFORUM_URL = ('http://forum.xda-developers.com/showthread.php?t=1415661')
myDONATE = ('http://forum.xda-developers.com/donatetome.php?u=2709018')
myREPO_TOOL_URL = ('https://dl-ssl.google.com/dl/googlesource/git-repo/repo')
myChangeLogUrlStable = ('https://raw.github.com/lithid/CMDC/master/debian/changelog')
# For dialogs
DialogError = gtk.MESSAGE_ERROR
# Keys to reading config
KeyRepoPath = 'repo_path'
KeyDevice = 'device'
KeyWinX = 'win_x'
KeyWinY = 'win_y'
# Device lists
dl_version = None
dl_url = None
dl_device = None
mylist = []
# Info stuff
AskConfirmInfo = ('<small>By no means what so ever is this software responsible for what you do to your phone. '
'You are taking the risks, you are choosing to this to your phone. By proceeding you are aware, you are warned. No crying or moaning. This software '
'was tested by human beings, not cybogs from your mothers closet. Please keep this in mind when something breaks, or hangs. If you have an issue '
'with this software, please let me know.\n\nBy clicking this ok button, you have given me your soul.\n\nPlay safe.\n\n</small> '
'<small><small><b>Note:\n- </b><i>This will not proceed unless you agree.</i></small>\n'
'<small><b>-</b><i> Cyanogenmod doesn\'t consider source builds offical, please keep this in mind if you plan on bug reporting.</i></small></small>\n\n'
'Any bugs? Please report them:\n\nhttp://github.com/lithid/AOSCompiler/issues\n')
about_info = ('The CyanogenMod Dev Center was written, not to dismiss the need'
'to learn the android system, but to release the need consistly remember menial tasks.\n\n'
'Please intend to learn the system, contribute back to any upstream.\n\n'
'Happy compiling,\n\nCode: Jeremie Long\n\n'
'Any bugs? Please report them\n'
'http://github.com/lithid/Cmcompiler/issues\n')
AdbList = (['All', 'Verbose', 'Debug', 'Info', 'Warning', 'Error', 'Fatal'])
AdbTooltipList = ['Show all log output', 'Only show verbose, low priority output', 'Only show debug output', 'Show information output', 'Show app and package warnings',
'Show application and package errors', 'Show critial or fatal errors']
ToolsComboList = ['View config', 'Repo path', 'Remove config', 'Add device', 'Open rom folder', 'Install packages', 'Install repo', 'Change background', 'About', 'Remove Repo']
LinkList = ["Gmail", "Twitter", "GooglePlus", "Xda", "Youtube", "Gallery"]
TermFrameTable = gtk.Table(1, 3, False)
StatusFrame = gtk.Frame()
MAIN_WIN = gtk.Window(gtk.WINDOW_TOPLEVEL)
DEV_BTN = gtk.Button()
runBtn = gtk.Button()
branchBtn = gtk.Button()
resetBtn = gtk.Button()
LinkContact = gtk.Label()
toolsLab = gtk.Label()
build_appLab = gtk.Label()
infoLab = gtk.Label()
runFrameLab = gtk.Label()
toggleAdbLab = gtk.Label()
toggleBashLab = gtk.Label()
resetLab = gtk.Label()
contactFrameLab = gtk.Label()
aoscTitleLab = gtk.Label()
checkCompile = gtk.CheckButton()
checkSync = gtk.CheckButton()
checkClobber = gtk.CheckButton()
checkTermToggle = gtk.CheckButton()
checkAdbToggle = gtk.CheckButton()
checkBashToggle = gtk.CheckButton()
packageEntryBox = gtk.Entry()
TERM = vte.Terminal()
TERM.set_font_from_string(myTermFont)
TERM.set_background_saturation(1.0)
class CyanogenMod():
URL = "https://github.com/CyanogenMod"
RAW_URL = "https://raw.github.com/CyanogenMod"
INIT_URL = "https://github.com/CyanogenMod/android.git"
JELLYBEAN_URL = "%s/android_vendor_cm/jellybean/jenkins-build-targets" % RAW_URL
ICS_URL = "%s/android_vendor_cm/ics/jenkins-build-targets" % RAW_URL
GINGERBREAD_URL = "%s/android_vendor_cyanogen/gingerbread/vendorsetup.sh" % RAW_URL
BranchList = ["gingerbread", "ics", "jellybean"]
def getBranch(self, arg):
CM = CyanogenMod()
b = Parser().read("branch").strip()
BR = None
if arg == "init":
BR = CM.INIT_URL
else:
if b == "gingerbread":
BR = CM.GINGERBREAD_URL
elif b == "ics":
BR = CM.ICS_URL
elif b == "jellybean":
BR = CM.JELLYBEAN_URL
else:
pass
return BR
def Compile(self):
r = Parser().read("repo_path")
d = Parser().read("device")
b = Parser().read("branch")
os.chdir(r)
m = Utils().getManu(d)
Globals.TERM.feed_child('clear\n')
if m == None:
if os.path.exists("build/tools/roomservice.py"):
Globals.TERM.feed_child('python build/tools/roomservice.py cm_%s\n' % d)
Dialogs().CDial(gtk.MESSAGE_INFO, "<small>Running roomservice</small>", "<small>Roomservice is running right now, you will have to run, \"<b>Compile</b>\" again after this is done downloading your kernel and device dependancies.</small>")
else:
Dialogs().CDial(gtk.MESSAGE_INFO, "Device manufacturer not found", "Make sure device exists and please try again")
return
else:
Parser().write("manuf", m)
Globals.TERM.feed_child('clear\n')
if not os.path.exists("%s/vendor/%s/%s" % (r, m, d)):
if Utils().is_adb_running() == True:
Globals.TERM.feed_child("cd %s/device/%s/%s/\n" % (r, m, d))
Globals.TERM.feed_child('clear\n')
Globals.TERM.feed_child('./extract-files.sh\n')
Globals.TERM.feed_child("cd %s\n" % r)
else:
Dialogs().CDial(gtk.MESSAGE_ERROR, "Adb isn't running", "Need adb to setup vendor files.\n\nIs this something you are going to do yourself?\n\nPlease try again.")
Globals.TERM.set_background_saturation(1.0)
Globals.TERM.feed_child('clear\n')
return
if not os.path.exists("%s/cacheran" % Globals.myCONF_DIR) and os.path.exists("prebuilt/linux-x86/ccache/ccache"):
os.chdir(r)
file("%s/cacheran" % Globals.myCONF_DIR, 'w').close()
Globals.TERM.feed_child('bash prebuilt/linux-x86/ccache/ccache -M 50G\n')
if os.path.exists("vendor/cm/get-prebuilts"):
Globals.TERM.feed_child('bash vendor/cm/get-prebuilts\n')
else:
Globals.TERM.feed_child('bash vendor/cyanogen/get-rommanager\n')
Globals.TERM.feed_child('source build/envsetup.sh\n')
Globals.TERM.feed_child("brunch %s\n" % d)
class FileChooser():
def getFolder(self):
# Define type of dialog
TYPE = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER
# Get response from the dialog
FOLDER = self.runDialog("Choose Folder...", TYPE)
# Only return a path if path selected exists.
if FOLDER:
if os.path.exists(FOLDER):
return FOLDER
else:
return None
def getFile(self):
# Define type of dialog
TYPE = gtk.FILE_CHOOSER_ACTION_OPEN
# Get response from the dialog
FILE = self.runDialog("Choose File...", TYPE)
# Only return a path if file selected exists.
if FILE:
if os.path.exists(FILE):
return FILE
else:
return None
def runDialog(self, name, arg):
direct = gtk.FileChooserDialog(name, action=arg, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
RESPONSE = direct.run()
MEH = direct.get_filename()
direct.destroy()
if RESPONSE == gtk.RESPONSE_ACCEPT:
return MEH
return None
class Utils():
CONFIG_DIR = Globals.myCONF_DIR
TOOLS_COMBO_LIST = Globals.ToolsComboList
KEY_DEVICE = Globals.KeyDevice
KEY_REPO_PATH = Globals.KeyRepoPath
KEY_WIN_X = Globals.KeyWinX
KEY_WIN_Y = Globals.KeyWinY
STR_USER_CONFIRM = Globals.StrUserConfirm
ASK_CONFIRM = Globals.AskConfirm
ASK_CONFIRM_INFO = Globals.AskConfirmInfo
LINK_LIST = Globals.LinkList
TARGET_OUT = Globals.TargetOut
DIALOG_ERROR = Globals.DialogError
TARGET_OUT = Globals.TargetOut
TERM_FRAME_TABLE = Globals.TermFrameTable
def is_adb_running(self):
running = False
cmd = commands.getoutput("adb devices")
x = cmd.split(" ")
print x
for i in x:
if "device\n" in i:
running = True
return running
def ViewConfig(self):
def btn(obj):
Globals().CDial(gtk.MESSAGE_INFO, "Configuration removed", "Your configuration has been removed. Please restart the application to re-configure.")
dialog = gtk.Dialog("CMCompiler", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_size_request(600, 400)
dialog.set_resizable(False)
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
sw.show()
table = gtk.Table(1, 1, False)
table.show()
sw.add_with_viewport(table)
frame = gtk.Frame()
frame.add(sw)
frame_label = gtk.Label()
frame_label.set_markup("Configuration:")
frame_label.show()
frame.set_label_widget(frame_label)
frame.set_border_width(15)
frame.show()
dialog.vbox.pack_start(frame, True, True, 0)
try:
f = open(Globals.myCONF)
count = 0
for line in f:
if "CMDC" in line:
pass
elif line == '\n':
pass
else:
count += 1
i = line.split("=")
x = i[0]
y = i[1]
label = gtk.Label()
label.set_markup("<b>%s:</b> <small>%s</small>" % (x, y))
label.show()
label.set_alignment(xalign=0, yalign=0)
label.set_padding(5, 5)
table.attach(label, 0, 1, count-1, count)
except IOError:
Dialogs().CDial(gtk.MESSAGE_ERROR, "Failed reading configuration", "Can't currently read the config file.\n\nIs it open somewhere else?\n\nPlease try again.")
dialog.run()
dialog.destroy()
def getManu(self, device):
s = None
FILE = "BoardConfig.mk"
if FILE is not None:
paths = glob("device/*/*/%s" % FILE)
else:
paths = None
if paths is not None:
for x in paths:
if device in x:
i = x.split("/")
i = i[1]
s = i
return s
def choose_branch(self, obj):
branchList = []
os.chdir("/tmp")
for x in commands.getoutput("git ls-remote --heads %s" % CyanogenMod().INIT_URL).split('\n'):
if x.startswith("sh:"):
Dialogs().CDial(gtk.MESSAGE_ERROR, "Git not found", "Can't find local git binary. \n\nPlease install it and try again.")
return
else:
BR = x.split("\t")[1]
branchList.append(BR)
def callback_branch(widget, data=None):
Parser().write("branch", data)
dialog = gtk.Dialog("Choose branch", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_size_request(300, 400)
dialog.set_resizable(False)
scroll = gtk.ScrolledWindow()
scroll.set_border_width(10)
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
dialog.vbox.pack_start(scroll, True, True, 0)
scroll.show()
table = gtk.Table(2, 1, False)
table.set_row_spacings(0)
scroll.add_with_viewport(table)
table.show()
device = gtk.RadioButton(None, None)
button_count = 0
for radio in branchList:
button_count += 1
button = gtk.RadioButton(group=device, label="%s" % (radio))
button.connect("toggled", callback_branch, radio)
table.attach(button, 0, 1, button_count-1, button_count, xoptions=gtk.FILL, yoptions=gtk.FILL)
button.show()
dialog.run()
dialog.destroy()
Update().main()
def Devices(self):
VERBOSE = Parser().read("verbose")
def callback_device(widget, data=None):
Parser().write("device", data)
BR = RepoHelper().getBranchUrl()
if BR == None:
return
dialog = gtk.Dialog("Choose device for Cyanogenmod", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_size_request(260, 400)
dialog.set_resizable(False)
scroll = gtk.ScrolledWindow()
scroll.set_border_width(10)
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
dialog.vbox.pack_start(scroll, True, True, 0)
scroll.show()
table = gtk.Table(2, 1, False)
table.set_row_spacings(5)
scroll.add_with_viewport(table)
table.show()
device = gtk.RadioButton(None, None)
try:
filehandle = urllib.urlopen(BR)
except IOError:
Dialogs().CDial(gtk.MESSAGE_ERROR, "Can't read file!", "Can't read the file to setup devices!\n\nPlease check you internet connections and try again!")
button_count = 0
Log().send("Info", "Reading URL", BR)
DeviceList = []
if os.path.exists(Globals.myCustDeviceFile):
f = open(Globals.myCustDeviceFile, "r")
x = f.readlines()
f.close()
for line in x:
l = line.strip()
DeviceList.append("cm_%s" % l)
for line in filehandle.readlines():
DeviceList.append(line)
if DeviceList[0].strip().startswith("PRODUCT_MAKEFILES"):
for lines in DeviceList:
if not ":=" in lines:
radio = lines.strip()
button_count += 1
button = "button%s" % (button_count)
Log().send("Info", "Reading line %s" % lines, radio)
x = radio.split(".mk")
Log().send("Info", "mk file split", x)
radio = x[0]
x = radio.split("cyanogen_")
Log().send("Info", "spliting cyanogen_", x)
radio = x[1]
Log().send("Info", "Final", radio)
button = gtk.RadioButton(group=device, label="%s" % (radio))
button.connect("toggled", callback_device, "%s" % (radio))
table.attach(button, 0, 1, button_count-1, button_count, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
button.show()
else:
for lines in DeviceList:
if not "#" in lines:
line = lines.strip()
button_count += 1
button = "button%s" % (button_count)
try:
if line:
x = line.split(" ")
radio = x[1]
else:
break
except:
radio = line.strip()
Log().send("Info", "Reading line %s" % line, radio)
x = radio.split("-")
Log().send("Info", "mk file split \"-\"", x)
radio = x[0]
x = radio.split("_")
Log().send("Info", "mk file split \"_\"", x)
number = len(x)
Log().send("Info", "Giving it a number", number)
if number is not 2:
f = x[1]
b = x[2]
radio = "%s_%s" % (f, b)
Log().send("Info", "Not 2 for number", radio)
else:
radio = x[1]
Log().send("Info", "Is 1 for number", radio)
button = gtk.RadioButton(group=device, label="%s" % (radio))
button.connect("toggled", callback_device, "%s" % (radio))
table.attach(button, 0, 1, button_count-1, button_count, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
button.show()
filehandle.close()
dialog.run()
dialog.destroy()
def ResetTerm(self):
Globals.checkAdbToggle.set_active(False)
Globals.TERM.set_background_saturation(1.0)
Globals.TERM.fork_command('clear')
Log().send("Info", "ResetTerm", "Terminal has been reset")
def choose_repo_path(self):
RESPONSE = FileChooser().getFolder()
if RESPONSE is not None:
Log().send("Info", "choose_repo_path", "Writing repo path of:\n%s" % RESPONSE)
Parser().write("repo_path", RESPONSE)
Update().main()
def cust_background_dialog(self):
IMG = FileChooser().getFile()
Log().send("Info", "cust_background_dialog", "Checking image by name:\n%s" % IMG)
if IMG is not None:
import imghdr as im
test = im.what(IMG)
if test:
Log().send("Info", "cust_background_dialog", "Image is good, writing it now")
Parser().write("background", IMG)
Update().background()
else:
Dialogs().CDial(gtk.MESSAGE_ERROR, "File not an image!", "Please use images for backgrounds!\n\nFile:\n%s" % IMG)
return
def run_custom_device(self):
title = "Setup custom device"
message = "Please setup your device here:"
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK)
dialog.set_markup(title)
dialog.format_secondary_markup(message)
table = gtk.Table(8, 1, False)
dialog.vbox.pack_start(table)
label = gtk.Label()
label.set_markup("Device name:")
label.show()
entry = gtk.Entry()
entry.show()
label1 = gtk.Label()
label1.set_markup("Device manufacturer:")
label1.show()
entry1 = gtk.Entry()
entry1.show()
label2 = gtk.Label()
label2.set_markup("Device tree url:")
label2.show()
entry2 = gtk.Entry()
entry2.show()
label3 = gtk.Label()
label3.set_markup("Device tree branch:")
label3.show()
entry3 = gtk.Entry()
entry3.show()
table.attach(label, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(entry, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(label1, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(entry1, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(label2, 0, 1, 4, 5, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(entry2, 0, 1, 5, 6, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(label3, 0, 1, 6, 7, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.attach(entry3, 0, 1, 7, 8, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
table.show()
q = dialog.run()
if q == gtk.RESPONSE_OK:
print "Here"
n = entry.get_text()
m = entry1.get_text()
u = entry2.get_text()
b = entry3.get_text()
if n == "" or m == "" or u == "" or b== "" :
print n, m, u, b
return
r = Parser().read("repo_path")
os.chdir(r)
manu_path = "%s/device/%s" % (r,m)
try:
if not os.path.exists(manu_path):
os.mkdir(manu_path)
except OSError:
Dialogs().CDial(gtk.MESSAGE_ERROR, "No Path Found", "Can't find all the paths, are you sure the repo has been synced?")
return
if os.path.exists("%s/%s" % (manu_path, n)):
shutil.rmtree("%s/%s" % (manu_path, n))
if not os.path.exists(Globals.myCustDeviceFile):
open(Globals.myCustDeviceFile,"w").close()
f = open(Globals.myCustDeviceFile,"a")
f.write("%s\n" % n)
f.close()
os.chdir(manu_path)
Globals.TERM.set_background_saturation(0.3)
Globals.TERM.fork_command('bash')
Globals.TERM.feed_child('git clone %s -b %s %s\n' % (u,b,n))
else:
Dialogs().CDial(gtk.MESSAGE_INFO, "Skipping this", "No changes have been made!")
dialog.destroy()
def choose_adb(self):
VERBOSE = Parser().read("verbose")
List = []
global ADB_TYPE
ADB_TYPE = None
ADB_LIST = Globals.AdbList
TIP_LIST = Globals.AdbTooltipList
for x in ADB_LIST:
List.append(x)
def callback_branch(widget, data=None):
global ADB_TYPE
ADB_TYPE = data
if VERBOSE == True:
print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
dialog = gtk.Dialog("Choose adb type", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_size_request(225, 233)
dialog.set_resizable(False)
scroll = gtk.ScrolledWindow()
scroll.set_border_width(10)
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
dialog.vbox.pack_start(scroll, True, True, 0)
scroll.show()
table = gtk.Table(2, 1, False)
table.set_row_spacings(0)
scroll.add_with_viewport(table)
table.show()
device = gtk.RadioButton(None, None)
button_count = 0
for radio in List:
button_count += 1
tooltip = gtk.Tooltips()
button = gtk.RadioButton(group=device, label="%s" % (radio))
button.connect("toggled", callback_branch, radio)
tooltip.set_tip(button, TIP_LIST[button_count-1])
table.attach(button, 0, 1, button_count-1, button_count, xoptions=gtk.FILL, yoptions=gtk.FILL)
button.show()
r = dialog.run()
dialog.destroy()
if r == gtk.RESPONSE_ACCEPT:
if ADB_TYPE:
return (ADB_TYPE[0], ADB_TYPE)
else:
return None
else:
return None
def change_background(self):
def chbutton(widget, data=None):
global WHICH
WHICH = data
BLIST = ["Custom", "Default"]
global WHICH
WHICH = None
dialog = gtk.Dialog("Change background", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_size_request(225, 233)
dialog.set_resizable(False)
hbox = gtk.HBox(False, 10)
hbox.show()
TYPE = gtk.RadioButton(None, None)
for radio in BLIST:
frame = gtk.Frame()
frame.set_label(radio)
frame.show()
button = gtk.RadioButton(group=TYPE, label="%s" % (radio))
button.connect("toggled", chbutton, radio)
frame.add(button)
hbox.add(frame)
button.show()
dialog.vbox.pack_start(hbox, True, True, 0)
r = dialog.run()
dialog.destroy()
if r == gtk.RESPONSE_ACCEPT:
if WHICH is "Default":
Parser().write("background", None)
Update().background()
elif WHICH is "Custom":
self.cust_background_dialog()
else:
return None
else:
return None
def press_link_button(self, obj, event, arg):
T = True
if arg == "Gmail":
url = "mailto:[email protected]"
elif arg == "Twitter":
url = "http://twitter.com/lithid"
elif arg == "GooglePlus":
url = "https://plus.google.com/u/0/103024643047948973176/posts"
elif arg == "Xda":
url = "http://forum.xda-developers.com/showthread.php?t=1789190"
elif arg == "Youtube":
url = "http://www.youtube.com/user/MrLithid"
elif arg == "Gallery":
url = "mailto:[email protected]"
else:
T = None
url = None
if T is not None:
subprocess.call(('xdg-open', url))
else:
Dialogs().CDial(DIALOG_ERROR, "No Url found!", "There is something wrong with the app. Report this. Returned: %s" % arg)
def openBuildFolder(self):
r = Parser().read(self.KEY_REPO_PATH)
d = Parser().read(self.KEY_DEVICE)
t = self.TARGET_OUT % (r, d)
if os.path.exists(t):
subprocess.call(('xdg-open', t))
else:
Dialogs().CDial(self.DIALOG_ERROR, 'No out folder', 'Need to compile before you can do this silly!')
def chk_config(self):
if not os.path.exists(self.CONFIG_DIR):
os.makedirs(self.CONFIG_DIR)
def get_askConfirm(self):
def askedClicked():
if not os.path.exists(self.ASK_CONFIRM):
file(self.ASK_CONFIRM, 'w').close()
q = Dialogs().QDial(self.STR_USER_CONFIRM, self.ASK_CONFIRM_INFO)
if q == True:
askedClicked()
else:
exit()
def run_vt_command(self, event):
i = Globals.packageEntryBox.get_text()
r = Parser().read(self.KEY_REPO_PATH)
d = Parser().read(self.KEY_DEVICE)
b = Parser().read('branch')
MAKE = Tools().processor()
if not os.path.exists("%s/.repo" % r):
RepoHelper().run_no_repo_found()
return
os.chdir(r)
Globals.TERM.set_background_saturation(0.3)
Globals.TERM.fork_command('bash')
Globals.TERM.feed_child('clear\n')
Globals.TERM.feed_child('. build/envsetup.sh\n')
wh = Tools().grep("%s/vendor/" % r, "cm_%s-userdebug" % d, "Run")
if wh:
Globals.TERM.feed_child('lunch cm_%s-userdebug\n' % d)
else:
Globals.TERM.feed_child('lunch cm_%s-eng\n' % d)
Globals.TERM.feed_child('time make -j%s %s\n' % (MAKE, i))
def run_local_shell(self):
self.ResetTerm()
Globals.TERM.set_background_saturation(0.3)
Globals.TERM.fork_command('bash')
def remove_repo(self):
RMBUTTON = gtk.Button()
REPO_NAME = None
REPOS = Tools().custom_list_dir(Globals.myHOME, ".repo")
if REPOS is None:
Dialogs().CDial(gtk.MESSAGE_INFO, "No repos configured.", "There are not repos configured. Please sync a repo first!")
return
def callback_radio(widget, data=None):
L = data.split("/")
L = L[-1]
RMBUTTON.set_label("Remove: %s" % L)
global REPO_NAME
REPO_NAME = data
def del_repo_paths(widget):
global REPO_NAME
REPO_NAME = str(REPO_NAME.strip())
if REPO_NAME is not "None":
q = Dialogs().QDial("Remove repos: %s?" % REPO_NAME, "Are you sure you want to remove:\n %s\n\nOnce this is done it can't be undone." % REPO_NAME)
if q is not True:
return
if REPO_NAME == "All":
for x in REPOS:
if os.path.isdir(x):
if Parser().read("repo_path") == x:
Parser().write("repo_path", Globals.myDEF_REPO_PATH)
shutil.rmtree(x)
dialog.destroy()
Update().main()
elif REPO_NAME == "None":
pass
else:
if os.path.isdir(REPO_NAME):
if Parser().read("repo_path") == REPO_NAME:
Parser().write("repo_path", Globals.myDEF_REPO_PATH)
shutil.rmtree(REPO_NAME)
dialog.destroy()
Update().main()
dialog = gtk.Dialog("Remove installed repos", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.set_size_request(500, 400)
dialog.set_resizable(False)
scroll = gtk.ScrolledWindow()
scroll.set_border_width(10)
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
scroll.set_size_request(400, 325)
dialog.vbox.pack_start(scroll, True, True, 0)
scroll.show()
table = gtk.Table(2, 1, False)
table.set_row_spacings(5)
scroll.add_with_viewport(table)
table.show()
radiobtn = gtk.RadioButton(None, None)
button_count = 0
REPOS.append("All")
REPOS.append("None")
for radio in REPOS:
button_count+=1
button = gtk.RadioButton(group=radiobtn, label="%s" % (radio))
button.connect("toggled", callback_radio, "%s" % (radio))
table.attach(button, 0, 1, button_count-1, button_count, xoptions=gtk.FILL, yoptions=gtk.SHRINK)
button.show()
RMBUTTON.set_label("Remove: None")
RMBUTTON.connect("clicked", del_repo_paths)
RMBUTTON.show()
dialog.vbox.pack_start(RMBUTTON, True, True, 0)
dialog.run()
dialog.destroy()
def device_button(self, event):
self.Devices()
Update().main()
def run_button(self, event):
isit = None
r = Parser().read("repo_path")
os.chdir(r)
Globals.TERM.set_background_saturation(0.3)
Globals.TERM.fork_command('clear')
Globals.TERM.fork_command('bash')
if Globals.checkClobber.get_active() == True:
isit = True
if not os.path.exists("%s/.repo" % r):
RepoHelper().run_no_repo_found()
Globals.TERM.set_background_saturation(1.0)
Globals.TERM.fork_command('clear')
return
Globals.TERM.feed_child('make clobber\n')
if Globals.checkSync.get_active() == True:
isit = True
C = Sync().run()
if C is False:
self.ResetTerm()
if Globals.checkCompile.get_active() == True:
isit = True
Compile().run()
if isit == None:
self.ResetTerm()
def remove_config(self):
q = Dialogs().QDial("Remove config?", "Are you sure you want to remove your current config?\n\nOnce this is done it can't be undone.")
if q == True:
os.remove(cmcconfig)
Dialogs().CDial(gtk.MESSAGE_INFO, "Configuration removed", "Your configuration has been removed. Please restart the application to re-configure.")
def start_adb(self):
if Utils().is_adb_running() == True:
(x, y) = self.choose_adb()
if x is not None: