forked from jrspruitt/OpenLFConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenLFConnect.py
executable file
·1495 lines (1161 loc) · 41.1 KB
/
OpenLFConnect.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
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 python
##############################################################################
# OpenLFConnect
#
# Copyright (c) 2012 Jason Pruitt <jrspruitt@gmail.com>
#
# This file is part of OpenLFConnect.
# OpenLFConnect is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenLFConnect is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenLFConnect. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
##############################################################################
# Title: OpenLFConnect
# Author: Jason Pruitt
# Email: jrspruitt@gmail.com
# IRC: #didj irc.freenode.org
# Wiki: http://elinux.org/LeapFrog_Pollux_Platform:_OpenLFConnect
##############################################################################
#@
# OpenLFConnect.py Version 1.0.2
import os
import cmd
import sys
import readline
from olcmodules.location import manager as loc_manager
from olcmodules import config
from olcmodules.system.networking import connection as net_connection
from olcmodules.system.mount import connection as mount_connection
from olcmodules.system.interface import config as conn_iface
from olcmodules.clients.pager import client as pager_client
from olcmodules.clients.dftp import client as dftp_client
from olcmodules.clients.didj import client as didj_client
from olcmodules.clients.local import client as local_client
from olcmodules.clients.interface import filesystem as fs_iface
from olcmodules.devices import profile
from olcmodules.firmware import cbf, packages
from olcmodules.firmware.images import ubi, jffs2
from olcmodules.firmware.initramfs import extract as irfs_extract
class OpenLFConnect(cmd.Cmd, object):
def __init__(self):
cmd.Cmd.__init__(self)
print 'OpenLFConnect Version 1.0.5'
self.debug = False
config.olc_files_dirs_check()
self._init_path = config.FILES_PATH.replace('\\', '/')
self._lm = loc_manager(self._init_path, cmd.Cmd)
self._dftp_client = None
self._didj_client = None
self._pager_client = None
profile_path_default = os.path.join(config.PROFILES_PATH, 'default.cfg')
self._profile_path = profile_path_default
self._profile = profile(profile_path_default)
self._profile.load(profile_path_default)
self._host_id = ''
self._device_id = ''
self._lm.set_local(self._lm.local_path)
readline.set_history_length(50)
##############################################################################
# OpenLFConnect.py
# Internal Functions
#######################
def error(self, e):
assert False, '%s' % e
def perror(self, e):
print '%s' % e
def emptyline(self):
pass
def cmdloop(self, intro=None):
while True:
try:
super(OpenLFConnect, self).cmdloop(intro="")
self.postloop()
except KeyboardInterrupt:
print '\n'
self.postloop()
sys.exit(0)
def emptyline(self):
pass
def postloop(self):
readline.write_history_file(config.HISTORY_FILE_PATH)
def preloop(self):
readline.read_history_file(config.HISTORY_FILE_PATH)
#######################
# Internal User Connection/Client Config Functions
# OpenLFConnect
#######################
def get_device_id(self):
return self._device_id
def set_device_id(self, did):
self._device_id = did
device_id = property(get_device_id, set_device_id)
def get_host_id(self):
return self._host_id
def set_host_id(self, hid):
self._host_id = hid
host_id = property(get_host_id, set_host_id)
##############################################################################
# Profile User Functions
# devices.profile
#######################
def complete_device_profile_load(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def complete_device_profile_default(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def do_device_profile_load(self, s):
"""
Usage:
device_profile_load <path>
Loads a device profile for the particular device you wish to use.
Standard profiles are in Extras/Profiles/*.cfg
"""
try:
self._lm.is_empty(s)
self._lm.set_local()
abspath = self._lm.get_abspath(s)
self._profile_path = abspath
self._lm.last_location()
self._profile.load(abspath)
except Exception, e:
self.perror(e)
def do_device_profile_name(self, s):
"""
Usage:
device_profile_name
Prints the file name of the currently loaded device profile
"""
print self._profile.get['olfc']['profile_name']
def do_device_profile_default(self, s):
"""
Usage:
device_profile_default <path>
Saves profile as the default profile loaded on startup.
If path isgiven will save that as default, with out loading contents.
If no path is given, saves currently loaded profile.
"""
try:
self._lm.set_local()
if s:
abspath = self._lm.get_abspath(s)
else:
abspath = self._profile_path
self._lm.last_location()
self._profile.save_as_default(abspath)
except Exception, e:
self.perror(e)
##############################################################################
# Didj Internal Functions
# clients.didj
#######################
def complete_didj_update_bootloader(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def complete_didj_update(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def complete_didj_update_firmware(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def complete_didj_update_eb(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def didj_device_info(self):
try:
print ' Device Name:\t\tDidj'
print ' Serial Number:\t%s' % self._didj_client.serial_number
print ' Battery Level:\t%s' % self._didj_client.battery_level
print ' Needs Repair:\t\t%s' % self._didj_client.needs_repair
print ' Device ID:\t\t%s' % self._lm.remote_conn.device_id
print ' Mount Point:\t\t%s' % self._lm.remote_conn.host_id
except Exception, e:
self.error(e)
#######################
# Didj User Functions
# clients.didj
#######################
def do_didj_mount(self, s):
"""
Usage:
didj_mount
Unlock Didj to allow it to mount on host system.
"""
try:
if not self._lm.is_client(self._didj_client):
try:
mc = conn_iface(mount_connection(self.device_id, self.host_id, self.debug))
self._didj_client = didj_client(mc, self.debug)
self._lm.remote_connection_init(mc, fs_iface(local_client(self.debug)), self._didj_client)
self._didj_client.mount()
self._lm.remote_path_init()
self.didj_device_info()
except Exception, e:
self._didj_client = None
self._lm.remote_destroy()
self.error(e)
else:
self.perror('Didj is already running.')
except Exception, e:
self.perror(e)
def do_didj_eject(self, s):
"""
Usage:
didj_eject
Eject the Didj which will unmount on host system, if the firmware updates are
on the Didj, an update will be triggered. If they are not, it will ask you
to unplug it.
Could take some time to unmount and eject if you have written files to
the device.
"""
try:
self._lm.is_remote(self._didj_client)
self._didj_client.eject()
self._lm.remote_destroy()
except Exception, e:
self.perror(e)
def do_didj_device_info(self, s):
"""
Usage:
didj_device_info
Returns various information about device and mount.
"""
try:
self._lm.is_remote(self._didj_client)
self.didj_device_info()
except Exception, e:
self.perror(e)
def do_didj_update(self, s):
"""
Usage:
didj_update <path>
CAUTION:
!!Attempts to flash firmware, could potentially be harmful.!!
!!Make sure Battery's are Fresh, or A/C adapter is used!!
Update Didj firmware and bootloader.
lightning-boot.bin, erootfs.jffs2 and kernel.bin are all required for the
update to work.
They can all be in the current directory, or in bootstrap-LF_LF1000 and
firmware-LF_LF1000 respectively.
MD5 files will be created automatically.
"""
try:
self._lm.is_remote(self._didj_client)
self._lm.set_local()
abspath = self._lm.get_abspath(s)
self._didj_client.upload_firmware(abspath)
self._didj_client.upload_bootloader(abspath)
if not self.debug:
self._didj_client.eject()
self._lm.last_location()
self._lm.remote_destroy()
else:
self._lm.last_location()
except Exception, e:
self._lm.last_location()
self.perror(e)
def do_didj_update_firmware(self, s):
"""
Usage:
didj_update_firmware <path>
CAUTION:
!!Attempts to flash firmware, could potentially be harmful.!!
!!Make sure Battery's are Fresh, or A/C adapter is used!!
Update Didj firmware.
erootfs.jffs2 and kernel.bin are both required for update to take place.
Files can have alternate names as long as their name is in the new name,
ex. custom-kernel.bin, or erootfs-custom.jffs2
Files must be in the current directory or in firmware-LF_LF1000 directory.
MD5 files will be created automatically.
"""
try:
self._lm.is_remote(self._didj_client)
self._lm.set_local()
abspath = self._lm.get_abspath(s)
self._didj_client.upload_firmware(abspath)
if not self.debug:
self._didj_client.eject()
self._lm.last_location()
self._lm.remote_destroy()
else:
self._lm.last_location()
except Exception, e:
self._lm.last_location()
self.perror(e)
def do_didj_update_bootloader(self, s):
"""
Usage:
didj_update_bootloader <path>
CAUTION:
!!Attempts to flash firmware, could potentially be harmful.!!
!!Make sure Battery's are Fresh, or A/C adapter is used!!
Update Didj bootloader.
File must be in current directory, bootloader-LF_LF1000 directory or direct
path to.
File can have alternate name, but must include lightning-boot in it,
ex custom-lightning-boot.bin
MD5 files will be created automatically.
"""
try:
self._lm.is_remote(self._didj_client)
self._lm.set_local()
abspath = self._lm.get_abspath(s)
self._didj_client.upload_bootloader(abspath)
if not self.debug:
self._didj_client.eject()
self._lm.last_location()
self._lm.remote_destroy()
else:
self._lm.last_location()
except Exception, e:
self._lm.last_location()
self.perror(e)
def do_didj_update_cleanup(self, s):
"""
Usage:
didj_update_cleaup
Remove Didj firmware and bootloader from device.
"""
try:
self._lm.is_remote(self._didj_client)
self._didj_client.cleanup()
except Exception, e:
self.perror(e)
def do_didj_update_eb(self, s):
"""
Usage:
didj_update_eb <path to emerald-boot>
CAUTION:
!!Attempts to flash firmware, could potentially be harmful.!!
!!Make sure Battery's are Fresh, or A/C adapter is used!!
!!Requires NAND enabled Emerald Boot!!
Flash Emerald Boot to Didj NAND.
After running Didj will shutdown, unplug USB and turn on device.
It should then turn itself off.
You should now be able to USB Boot like the Explorer and update using DFTP.
"""
try:
self._lm.is_empty(s)
self._lm.is_remote(self._didj_client)
self._lm.set_local()
abspath = self._lm.get_abspath(s)
self._didj_client.eb_update(abspath)
if not self.debug:
self._didj_client.eject()
self._lm.last_location()
self._lm.remote_destroy()
else:
self._lm.last_location()
except Exception, e:
self._lm.last_location()
self.perror(e)
##############################################################################
# DFTP Internal Functions
# clients.dftp
#######################
def complete_dftp_update(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def complete_dftp_run_script(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def dftp_device_info(self):
try:
device_name = self._dftp_client.device_name
serial = self._dftp_client.serial_number
print ' Device:\t\t%s' % device_name
print ' Firmware Version:\t%s' % self._dftp_client.firmware_version
print ' Serial Number\t\t%s' % serial
print ' Board ID:\t\t%s' % self._dftp_client.board_id
print ' Battery Level\t\t%s' % self._dftp_client.battery_level
if self._lm.remote_conn.host_id != '/':
print ' Device IP:\t\t%s' % self._lm.remote_conn.device_id
print ' Host IP:\t\t%s' % self._lm.remote_conn.host_id
print ' Host Name:\t\t%s-%s' % (device_name, serial)
else:
print ' Device ID:\t\t%s' % self._lm.remote_conn.device_id
print ' DFTP Version:\t\t%s' % self._dftp_client.dftp_version
except Exception, e:
self.error(e)
#######################
# DFTP User Functions
# clients.dftp
#######################
def do_dftp_connect(self, s):
"""
Usage:
dftp_connect
Connect to device for dftp session.
What version of DFTP it attempts to connect with depends on the device profile
that has been loaded.
Will attempt to configure IPs or mount points as needed.
This could take a minute or so, if you just booted the device.
"""
try:
if not self._lm.is_client(self._dftp_client):
try:
if self._profile.get['firmware']['dftp_version'] == 1:
ci = conn_iface(net_connection(self.host_id, self.device_id, self.debug))
print 'Connecting with DFTP v1 Networking.'
elif self._profile.get['firmware']['dftp_version'] == 2:
ci = conn_iface(mount_connection(self.device_id, 'NULL', self.debug))
print 'Connecting with DFTP v2 Mass Storage.'
self._dftp_client = dftp_client(ci, self._profile, self.debug)
self._lm.remote_connection_init(ci, fs_iface(self._dftp_client), self._dftp_client)
self._dftp_client.create_client()
self._lm.remote_path_init()
#self.dftp_device_info()
except Exception, e:
self._dftp_client = None
self._lm.remote_destroy()
self.error(e)
else:
self.perror('DFTP client already running.')
except Exception, e:
self.perror(e)
def do_dftp_disconnect(self, s):
"""
Usage:
dftp_disconnect
Disconnect DFTP client.
This will cause the DFTP server to start announcing its IP again,
except Explorer's surgeon.cbf version, which will reboot the device.
"""
try:
self._lm.is_remote(self._dftp_client)
self._dftp_client.disconnect()
self._dftp_client = None
self._lm.remote_destroy()
except Exception, e:
self.perror(e)
def do_dftp_device_info(self, s):
"""
Usage:
dftp_device_info
Returns various information about the device, and connection.
Note: Device name is guessed from board id.
"""
try:
self._lm.is_remote(self._dftp_client)
self.dftp_device_info()
except Exception, e:
self.perror(e)
def do_dftp_update(self, s):
"""
Usage:
dftp_update <local path>
CAUTION:
!!Attempts to flash firmware, could potentially be harmful.!!
!!Make sure Battery's are Fresh, or A/C adapter is used!!
Uploads and flashes the files found in path, or the file specified by path.
Caution: Has not been tested on LeapPad1, LeapPad2, or GS theoretically it
should work though, please confirm to author yes or no if you get the chance.
"""
try:
self._lm.is_remote(self._dftp_client)
self._lm.set_local()
abspath = self._lm.get_abspath(s)
self._dftp_client.update_firmware(abspath)
self._lm.last_location()
except Exception, e:
self._lm.last_location()
self.perror(e)
def do_dftp_reboot(self, s):
"""
Usage:
dftp_reboot
This will trigger a reboot.
"""
try:
self._lm.is_remote(self._dftp_client)
self._dftp_client.reboot()
self._dftp_client = None
self._lm.remote_destroy()
except Exception, e:
self._dftp_client = None
self._lm.remote_destroy()
self.perror(e)
def do_dftp_reboot_usbmode(self, s):
"""
Usage:
dftp_reboot_usbmode
This will reboot the device into USB mode, for sending a surgeon.cbf to boot.
If surgeon is booted, will do a standared reboot.
"""
try:
self._lm.is_remote(self._dftp_client)
self._dftp_client.reboot_usbmode()
self._dftp_client = None
self._lm.remote_destroy()
except Exception, e:
self._dftp_client = None
self._lm.remote_destroy()
self.perror(e)
def do_dftp_mount_patient(self, s):
"""
Usage:
dftp_mount_patient 0|1|2
Gives you access to the devices filesystem when running Surgeon.
0 Unmounts /patient-rfs and /patient-bulk/
1 Mounts /patient-rfs and /patient-bulk/
2 Mounts only /patient-rfs
"""
try:
self._lm.is_remote(self._dftp_client)
self._dftp_client.mount_patient(s)
except Exception, e:
self.perror(e)
def do_dftp_run_script(self, s):
"""
Usage:
dftp_run_script <path>
This takes a shell script as an argument, and proceeds to run it on the device.
"""
try:
self._lm.is_empty(s)
self._lm.is_remote(self._dftp_client)
self._lm.set_local()
path = self._lm.get_abspath(s)
self._dftp_client.run_script(path)
self._lm.last_location()
except Exception, e:
self._lm.last_location()
self.perror(e)
def do_send(self, s):
"""
Usage:
send <raw command>
Advanced use only, don't know, probably shouldn't.
"""
try:
self._lm.is_empty(s)
self._lm.is_remote(self._dftp_client)
self._dftp_client._connection.timeout(3)
self._dftp_client.send('%s\x00' % s)
ret = self._dftp_client.receive()
self._dftp_client._connection.timeout()
if ret:
print ret
except Exception, e:
self.perror(e)
##############################################################################
# Pager Internal Functions
# clients.pager
#######################
def complete_surgeon_boot(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
def complete_surgeon_extract_rootfs(self, text, line, begidx, endidx):
return self._lm.complete_1arg_local(text, line, begidx, endidx)
#######################
# Pager User Functions
# clients.pager
#######################
def do_surgeon_boot(self, s):
"""
Usage:
surgeon_boot <path to surgeon.cbf>
Uploads a Surgeon.cbf file to a device in USB Boot mode.
File can be any name, but must conform to CBF standards.
"""
try:
self._lm.is_empty(s)
self._pager_client = pager_client(self.debug)
abspath = self._lm.get_abspath(s)
if not self._lm.fs.is_dir(abspath):
self._pager_client = pager_client(conn_iface(mount_connection()))
self._pager_client.upload(abspath)
print 'Booting surgeon.'
self._pager_client = None
else:
self.error('Path is not a file.')
self._pager_client = None
except Exception, e:
self.perror(e)
def do_surgeon_extract_rootfs(self, s):
"""
Usage:
surgeon_extract_rootfs <rootfs suffix> <path to surgeon.cbf or zImage>
Extracts the Root file system (initramfs) to
<current directory>/rootfs.<suffix>
"""
try:
self._lm.is_empty(s)
if sys.platform != 'win32':
suffix, ipath = s.split(' ')
abspath = self._lm.get_abspath(ipath)
if not self._lm.fs.is_dir(abspath):
irfs_extract(abspath, suffix)
else:
self.error('Path is not a file.')
else:
self.error('Linux only command.')
except Exception, e:
self.perror(e)
##############################################################################
# UI User Complete Internal Functions
# OpenLFConnect
#######################
def complete_ls(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
def complete_cd(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
def complete_mkdir(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
def complete_rmdir(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
def complete_rm(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
def complete_download(self, text, line, begidx, endidx):
return self._lm.complete_remote(text, line, begidx, endidx)
def complete_upload(self, text, line, begidx, endidx):
return self._lm.complete_local(text, line, begidx, endidx)
def complete_cat(self, text, line, begidx, endidx):
return self._lm.complete_path(text, line, begidx, endidx)
##############################################################################
# OpenLFConnect UI Functions
#######################
#######################
# UI Connection/Client Config Functions
# Debug
# OpenLFConnect
#######################
def do_debug(self, s):
"""
Usage:
debug <on | off>
Turning debug on, turns most any filesystem action off, such as, up/download, rm,
mkdir, etc. It is replaced with text displaying what would have happened.
Useful for checking updates before they happen, also will not
eject Didj on update.
"""
if s.lower() in ('on', 'true', 'enable'):
self.debug = True
elif s.lower() in ('off', 'false', 'disable'):
self.debug = False
else:
self.perror('Could not determine action from option given.')
if self._lm.remote_conn:
self._lm.remote_conn.debug = self.debug
if self._lm.local_client:
self._lm.local_client.debug = self.debug
if self._lm.remote_client:
self._lm.remote_client.debug = self.debug
if self._lm.local_fs:
self._lm.local_fs.debug = self.debug
if self._lm.remote_fs:
self._lm.remote_fs.debug = self.debug
#######################
# UI User Connection/Client Config Functions
# Mount
# OpenLFConnect
#######################
def do_get_device_id(self, s):
"""
Usage:
get_dev_id
Returns the currently configured device id.
"""
return self.device_id
def do_set_device_id(self, s):
"""
Usage:
set_dev_id <device id>
Set the device to use when creating a new mount client.
The device id, in Linux is a harddrive /dev/sd[?],
or Windows the PhysicalDrive ex. PD1.
To reset to auto determine leave input blank.
"""
if s == '':
self.device_id = ''
else:
self.device_id = s
def do_get_mount_point(self, s):
"""
Usage:
get_mount_point
Returns the currently configured mount point to use when creating a
new mount client.
"""
return self.host_id
def do_set_mount_point(self, s):
"""
Usage:
set_mount_point <mount point>
Set the mount point to use when creating a new mount client.
The mount point, ex. Linux /media/didj, or Windows D:\
To reset to auto determine leave input blank.
"""
if s == '':
self.host_id = ''
else:
self.host_id = s
#######################
# UI Connection Config Functions
# Networking
# OpenLFConnect
#######################
def do_get_device_ip(self, s):
"""
Usage:
get_device_ip
Returns currently configured device IP to use when creating a new network client.
"""
return self.device_id
def do_set_device_ip(self, s):
"""
Usage:
set_device_ip <IP>
Set the device IP address to use when creating a new network client.
ex. 169.254.123.123
To reset to auto determine leave input blank.
"""
if s == '':
self.device_id = ''
else:
self.device_id = s
def do_get_host_ip(self, s):
"""
Usage:
get_host_ip
Returns currently configured host IP to use when creating a new network client.
"""
return self.host_id
def do_set_host_ip(self, s):
"""
Usage:
set_host_ip <IP>
Set the host IP address to use when creating a new network client.
ex. 169.254.123.123
To reset to auto determine leave input blank.
"""
if s == '':
self.host_id = ''
else:
self.host_id = s
#######################
# UI User Location Functions
# OpenLFConnect
#######################
def do_remote(self, s):
"""
Usage:
remote
Set to remote device for filesystem navigation.
"""
try:
self._lm.is_remote()
self._lm.set_remote()
except Exception, e:
self.perror(e)
def do_local(self, s):
"""
Usage:
local
Set to prompt to local host for filesystem navigation.
"""
try:
self._lm.set_local()
except Exception, e:
self.perror(e)
#######################
# UI Filesystem Functions
# OpenLFConnect
#######################
def do_cwdr(self, s):
"""
Usage:
cwdr
Print current remote directory path.
"""
print self._lm.remote_path
def do_cwdl(self, s):
"""
Usage:
cwdl
Print current local directory path.
"""
print self._lm.local_path
def do_exit(self, s):
"""
Usage:
exit
Exit OpenLFConnect
"""
self.postloop()