~ubuntu-branches/ubuntu/maverick/lfm/maverick-proposed

« back to all changes in this revision

Viewing changes to .pc/ignore_COPYING.patch/lfm/actions.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Silva
  • Date: 2010-05-24 16:55:24 UTC
  • mfrom: (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100524165524-zhiei3a9fb345fvh
Tags: 2.2-1
New Upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    curses.KEY_DOWN: 'cursor_down',
36
36
    curses.KEY_PPAGE: 'page_previous',
37
37
    curses.KEY_BACKSPACE: 'page_previous',
38
 
    0x02: 'page_previous',     # Ctrl-B
 
38
    0x02: 'page_previous',          # Ctrl-B
39
39
    curses.KEY_NPAGE: 'page_next',
40
40
    ord(' '): 'page_next',
41
 
    0x06: 'page_next',         # Ctrl-F
 
41
    0x06: 'page_next',              # Ctrl-F
42
42
    curses.KEY_HOME: 'home',
43
 
    0x01: 'home',              # Ctrl-A
 
43
    0x01: 'home',                   # Ctrl-A
44
44
    curses.KEY_END: 'end',
45
 
    0x05: 'end',               # Ctrl-E
46
 
 
 
45
    0x05: 'end',                    # Ctrl-E
 
46
    0x0C: 'cursor_center',          # Ctrl-L
 
47
    0x10: 'cursor_quarter_up',      # Ctrl-P
 
48
    0x231: 'cursor_quarter_up',     # Ctrl-Cursor_up
 
49
    0x0e: 'cursor_quarter_down',    # Ctrl-N
 
50
    0x208: 'cursor_quarter_down',   # Ctrl-Cursor_down
 
51
        
47
52
    # movement other pane
48
53
    curses.KEY_SR: 'cursor_up_otherpane',        # Shift-up
49
54
    0x22f: 'cursor_up_otherpane',                # Alt-up, kUP3
61
66
    0x21a: 'cursor_left_otherpane',              # Alt-left, kLFT3
62
67
    curses.KEY_SRIGHT: 'cursor_right_otherpane', # Shift-right
63
68
    0x229: 'cursor_right_otherpane',             # Alt-right, kRIT3
64
 
    
 
69
    ord('P'): 'cursor_quarter_up_otherpane',     # P
 
70
    ord('N'): 'cursor_quarter_down_otherpane',   # N
 
71
 
65
72
    # change dir
66
73
    curses.KEY_LEFT: 'cursor_left',
67
74
    curses.KEY_RIGHT: 'cursor_right',
117
124
    ord('t'): 'touch_file',
118
125
    ord('T'): 'touch_file',
119
126
    ord('l'): 'create_link',
120
 
    ord('L'): 'create_link',
121
 
    0x0C: 'edit_link',          # Ctrl-L
 
127
    ord('L'): 'edit_link',
122
128
    0x0F: 'open_shell',         # Ctrl-O
123
129
 
124
130
    # main functions
198
204
    tab.fix_limits()
199
205
    return RET_HALF_UPDATE
200
206
 
 
207
def cursor_center(tab):
 
208
    tab.file_i = tab.file_a + int(tab.pane.dims[0]/2)
 
209
    if tab.pane.mode in (PANE_MODE_LEFT, PANE_MODE_RIGHT):
 
210
        tab.file_i -= 1
 
211
    tab.fix_limits()
 
212
    return RET_HALF_UPDATE
 
213
 
 
214
def cursor_quarter_up(tab):
 
215
    delta = int(tab.pane.dims[0]/4)
 
216
    tab.file_i -= delta
 
217
    tab.fix_limits()
 
218
    return RET_HALF_UPDATE
 
219
 
 
220
def cursor_quarter_down(tab):
 
221
    delta = int(tab.pane.dims[0]/4)
 
222
    tab.file_i += delta
 
223
    tab.fix_limits()
 
224
    return RET_HALF_UPDATE  
201
225
 
202
226
# movement other pane
203
227
def cursor_up_otherpane(tab):
276
300
        enter(othertab, allowexec=False)
277
301
        return RET_HALF_UPDATE_OTHER
278
302
 
 
303
def cursor_quarter_up_otherpane(tab):
 
304
    if app.prefs.options['manage_otherpane'] and \
 
305
            tab.pane.mode in (PANE_MODE_LEFT, PANE_MODE_RIGHT):
 
306
        delta = int(tab.pane.dims[0]/4)
 
307
        othertab = app.noact_pane.act_tab
 
308
        othertab.file_i -= delta
 
309
        othertab.fix_limits()
 
310
        return RET_HALF_UPDATE_OTHER
 
311
    else:
 
312
        return RET_NO_UPDATE
 
313
 
 
314
def cursor_quarter_down_otherpane(tab):
 
315
    if app.prefs.options['manage_otherpane'] and \
 
316
            tab.pane.mode in (PANE_MODE_LEFT, PANE_MODE_RIGHT):
 
317
        delta = int(tab.pane.dims[0]/4)
 
318
        othertab = app.noact_pane.act_tab
 
319
        othertab.file_i += delta
 
320
        othertab.fix_limits()
 
321
        return RET_HALF_UPDATE_OTHER
 
322
    else:
 
323
        return RET_NO_UPDATE
279
324
    
280
325
# change dir
281
326
def cursor_left(tab):
295
340
        tab.enter_dir(filename)
296
341
    elif typ == files.FTYPE_LNK2DIR:
297
342
        tab.init(files.get_linkpath(tab.path, filename))
298
 
    elif typ in (files.FTYPE_REG, files.FTYPE_LNK) and vfstype != None:
 
343
    elif typ in (files.FTYPE_REG, files.FTYPE_LNK) and vfstype is not None:
299
344
        vfs.init(tab, filename, vfstype)
300
345
    elif typ == files.FTYPE_EXE and allowexec:
301
346
        do_execute_file(tab)
332
377
    tab.pane.display()
333
378
    t = Tree(tab.path, tab.pane.mode)
334
379
    ans = t.run()
335
 
    del(t)
 
380
    del t
336
381
    app.act_pane, app.noact_pane = app.act_pane, app.noact_pane
337
382
    if ans != -1:
338
383
        tab.init(ans)
540
585
    if not newfile:
541
586
        return
542
587
    fullfilename = os.path.join(tab.path, newfile)
543
 
    i, err = os.popen4('touch \"%s\"' % get_escaped_filename(fullfilename))
544
 
    err = err.read().split(':')[-1:][0].strip()
 
588
    cmd = 'touch \"%s\"' % get_escaped_filename(fullfilename)
 
589
    err = get_shell_output(cmd)
545
590
    if err:
 
591
        err = err.split(':')[-1:][0].strip()
546
592
        app.display()
547
593
        messages.error('Touch file', '%s: %s' % (newfile, err))
548
594
    else:
596
642
 
597
643
 
598
644
# main functions
 
645
def __rename_backup_helper(tab):
 
646
    if tab.selections:
 
647
        fs = tab.selections[:]
 
648
    else:
 
649
        filename = tab.get_file()
 
650
        if filename == os.pardir:
 
651
            return
 
652
        fs = [filename]
 
653
    return fs
 
654
 
 
655
def rename(tab):
 
656
    fs = __rename_backup_helper(tab)
 
657
    res = ProcessLoopRename('Rename files', files.do_rename, fs, tab.path).run()
 
658
    tab.selections = []
 
659
    tab.refresh()
 
660
    app.regenerate()
 
661
 
 
662
def backup_file(tab):
 
663
    fs = __rename_backup_helper(tab)
 
664
    try:
 
665
        # pc is not used, just to check files have valid encoding
 
666
        pc = files.PathContents(fs, tab.path)
 
667
    except UnicodeError:
 
668
        messages.error('Backup files', 'Files with invalid encoding, convert first')
 
669
        return
 
670
    res = ProcessLoopBackup('Backup files', files.do_backup, fs, tab.path,
 
671
                            app.prefs.misc['backup_extension']).run()
 
672
    tab.selections = []
 
673
    tab.refresh()
 
674
    app.regenerate()
 
675
 
599
676
def view_file(tab):
600
677
    do_view_file(tab)
601
678
 
602
679
def edit_file(tab):
603
680
    do_edit_file(tab)
604
681
 
 
682
def __copymove_helper(destdir, path, fs):
 
683
    if destdir[0] != os.sep:
 
684
        destdir = os.path.join(path, destdir)
 
685
    dest_is_file = os.path.isfile(destdir)
 
686
    dest_exists = os.path.exists(destdir)
 
687
    # special case: no copy/move multiple files or dir over an existing file
 
688
    if len(fs) > 1 and (dest_is_file or not dest_exists):
 
689
        messages.error('Copying files \'%s\'' % destdir,
 
690
                       'Not a directory (20)')
 
691
        return -1, None, None 
 
692
    for f in fs:
 
693
        if os.path.isdir(os.path.join(path, f)) and dest_is_file:
 
694
            messages.error('Copying files \'%s\'' % destdir,
 
695
                           'Not a directory (20)')
 
696
            return -1, None, None 
 
697
    # special case: copy/move a dir to same path with different name
 
698
    rename_dir = False
 
699
    for f in fs:
 
700
        if os.path.isdir(os.path.join(path, f)) and not dest_exists:
 
701
            rename_dir = True
 
702
            break
 
703
    # special case: no copy/move to "<path>/non-existing-dir/not-existing-name"
 
704
    #               but permit copy/move to "<path>/not-existing-name"
 
705
    dir_destdir = os.path.dirname(destdir)
 
706
    # not (a and b) = not a or not b
 
707
    # if os.path.dirname(destdir) != path and \
 
708
    #         not (os.path.isdir(os.path.dirname(destdir)) and not dest_exists):
 
709
    if dir_destdir != path and (not os.path.isdir(dir_destdir) or dest_exists):
 
710
        for f in fs:
 
711
            src = os.path.join(path, f)
 
712
            dest = os.path.join(destdir, f)
 
713
            if not os.path.exists(dest) and not dest_exists:
 
714
                messages.error(dest, destdir)
 
715
                messages.error('Copying files \'%s\'' % destdir,
 
716
                               'No such file or directory (2)')
 
717
                return -1, None, None 
 
718
    return 0, destdir, rename_dir 
 
719
 
605
720
def copy(tab):
606
721
    destdir = app.noact_pane.act_tab.path + os.sep
607
722
    if tab.selections:
615
730
        fs = [filename]
616
731
    destdir = doEntry(tab.path, 'Copy', buf, destdir)
617
732
    if destdir:
618
 
        res = ProcessCopyMoveLoop('Copying files', files.copy,
619
 
                                  fs, tab.path, destdir).run()
 
733
        st, destdir, rename_dir = __copymove_helper(destdir, tab.path, fs)
 
734
        if st == -1:
 
735
            return
 
736
        try:
 
737
            pc = files.PathContents(fs, tab.path)
 
738
        except UnicodeError:
 
739
            app.display()
 
740
            messages.error('Copy files', 'Files with invalid encoding, convert first')
 
741
            return
 
742
        res = ProcessLoopCopy('Copy files', files.do_copy, pc,
 
743
                              destdir, rename_dir).run()
620
744
        tab.selections = []
621
745
        app.regenerate()
622
 
 
 
746
        
623
747
def move(tab):
624
748
    destdir = app.noact_pane.act_tab.path + os.sep
625
749
    if tab.selections:
633
757
        fs = [filename]
634
758
    destdir = doEntry(tab.path, 'Move', buf, destdir)
635
759
    if destdir:
636
 
        res = ProcessCopyMoveLoop('Moving files', files.move,
637
 
                                  fs, tab.path, destdir).run()
 
760
        st, destdir, rename_dir = __copymove_helper(destdir, tab.path, fs)
 
761
        if st == -1:
 
762
            return
 
763
        try:
 
764
            pc = files.PathContents(fs, tab.path)
 
765
        except UnicodeError:
 
766
            app.display()
 
767
            messages.error('Move files', 'Files with invalid encoding, convert first')
 
768
            return
 
769
        res = ProcessLoopCopy('Move files', files.do_copy, pc,
 
770
                              destdir, rename_dir).run()
 
771
        if res != -1: # stopped by user
 
772
            if isinstance(res, list): # don't delete files when not overwritten
 
773
                pc.remove_files(res)
 
774
            tmp_delete_all = app.prefs.confirmations['delete']
 
775
            app.prefs.confirmations['delete'] = 0
 
776
            res = ProcessLoopDelete('Move files', files.do_delete, pc).run()
 
777
            app.prefs.confirmations['delete'] = tmp_delete_all
638
778
        tab.selections = []
639
779
        tab.refresh()
640
780
 
641
 
def rename(tab):
642
 
    if tab.selections:
643
 
        fs = tab.selections[:]
644
 
    else:
645
 
        filename = tab.get_file()
646
 
        if filename == os.pardir:
647
 
            return
648
 
        fs = [filename]
649
 
    res = ProcessRenameLoop('Renaming files', files.move, fs, tab.path).run()
650
 
    tab.selections = []
651
 
    tab.refresh()
652
 
    app.regenerate()
653
 
 
654
781
def make_dir(tab):
655
782
    newdir = doEntry(tab.path, 'Make directory', 'Type directory name')
656
783
    if newdir:
658
785
        if ans:
659
786
            app.display()
660
787
            messages.error('Make directory',
661
 
                           '%s (%s)' % (ans, newdir))
 
788
                           '%s (%s)' % ans)
662
789
        else:
663
790
            app.regenerate()
664
791
 
670
797
        if filename == os.pardir:
671
798
            return
672
799
        fs = [filename]
673
 
    res = ProcessDeleteLoop('Deleting files', files.delete, fs, tab.path).run()
 
800
    try:
 
801
        pc = files.PathContents(fs, tab.path)
 
802
    except UnicodeError:
 
803
        messages.error('Delete files', 'Files with invalid encoding, convert first')
 
804
        return
 
805
    res = ProcessLoopDelete('Delete files', files.do_delete, pc).run()
674
806
    tab.selections = []
675
807
    tab.refresh()
676
808
 
699
831
    menu = [ '@    Do something on file(s)',
700
832
             'i    File info',
701
833
             'p    Change file permissions, owner, group',
 
834
             'a    Backup file',
702
835
             'g    Gzip/gunzip file(s)',
703
836
             'b    Bzip2/bunzip2 file(s)',
704
 
             'x    Uncompress .tar.gz, .tar.bz2, .zip, .rar, .7z',
 
837
             'h    Xz/unxz file(s)',
 
838
             'x    Uncompress .tar.gz, .tar.bz2, .tar.xz, .zip, .rar, .7z',
705
839
             'u    Uncompress .tar.gz, etc in other panel',
706
840
             'c    Compress directory to .tar.gz',
707
841
             'd    Compress directory to .tar.bz2',
 
842
             'e    Compress directory to .tar.xz',
708
843
             'z    Compress directory to .zip',
709
844
             'r    Compress directory to .rar',
710
845
             '7    Compress directory to .7z' ]
719
854
        do_show_file_info(tab)
720
855
    elif cmd == 'p':
721
856
        do_change_perms(tab)
 
857
    elif cmd == 'a':
 
858
        backup_file(tab)
722
859
    elif cmd == 'g':
723
860
        compress_uncompress_file(tab, 'gz')
724
861
    elif cmd == 'b':
725
862
        compress_uncompress_file(tab, 'bz2')
 
863
    elif cmd == 'h':
 
864
        compress_uncompress_file(tab, 'xz')
726
865
    elif cmd == 'x':
727
866
        uncompress_dir(tab, tab.path)
728
867
    elif cmd == 'u':
731
870
        compress_dir(tab, 'tgz')
732
871
    elif cmd == 'd':
733
872
        compress_dir(tab, 'tbz2')
 
873
    elif cmd == 'e':
 
874
        compress_dir(tab, 'txz')
734
875
    elif cmd == 'z':
735
876
        compress_dir(tab, 'zip')
736
877
    elif cmd == 'r':
830
971
        lst = tab.files.keys()
831
972
    dirs = [d for d in lst if tab.files[d][files.FT_TYPE] in \
832
973
                (files.FTYPE_DIR, files.FTYPE_LNK2DIR) and d != os.pardir]
833
 
    res = ProcessDirSizeLoop('Calculate Directories Size',
 
974
    res = ProcessLoopDirSize('Calculate Directories Size',
834
975
                             do_show_dirs_size, dirs, tab.path).run()
835
 
    if res != None and type(res) == type([]) and len(res):
 
976
    if res is not None and isinstance(res, list) and len(res):
836
977
        for i, d in enumerate(dirs):
837
978
            try:
838
979
                tab.files[d] = res[i]
848
989
                  'd': files.SORTTYPE_byDate, 'D': files.SORTTYPE_byDate_rev }
849
990
    while True:
850
991
        ch = messages.get_a_key('Sorting mode',
851
 
                                'N(o), by (n)ame, by (s)ize, by (d)ate,\nuppercase if reversed order, Ctrl-C to quit')
 
992
                                'N(o), by (n)ame, by (s)ize, by (d)ate,\nuppercase if reverse order, Ctrl-C to quit')
852
993
        if ch == -1:                 # Ctrl-C
853
994
            break
854
995
        elif 32 <= ch < 256 and chr(ch) in sorttypes.keys():
895
1036
 
896
1037
# do view file
897
1038
def do_view_file(tab):
898
 
    run_on_current_file('pager', tab)
 
1039
    run_on_current_file('pager', tab.get_fullpathfile())
899
1040
 
900
1041
 
901
1042
# do edit file
902
1043
def do_edit_file(tab):
903
 
    run_on_current_file('editor', tab)
 
1044
    run_on_current_file('editor', tab.get_fullpathfile())
904
1045
    app.regenerate()
905
1046
 
906
1047
 
908
1049
def do_execute_file(tab):
909
1050
    filename = tab.get_file()
910
1051
    parms = doEntry(tab.path, 'Execute file', 'Enter arguments')
911
 
    if parms == None:
 
1052
    if parms is None:
912
1053
        return
913
1054
    elif parms == '':
914
1055
        cmd = get_escaped_filename(filename)
915
1056
    else:
916
 
        cmd = '%s \"%s\"' % (get_escaped_filename(filename), parms)
 
1057
        cmd = '%s %s' % (get_escaped_filename(filename), parms)
917
1058
    curses.endwin()
918
 
    st, msg = ProcessFunc('Executing file', filename,
919
 
                          run_shell, cmd, tab.path, True).run()
 
1059
    st, msg = ProcessFunc('Executing file', encode(filename),
 
1060
                          run_shell, cmd, encode(tab.path), True).run()
920
1061
    if st == -1:
921
1062
        messages.error('Executing file', msg)
922
 
    if st != -100 and msg != None:
 
1063
    if st != -100 and msg is not None:
923
1064
        if app.prefs.options['show_output_after_exec']:
924
1065
            curses.curs_set(0)
925
1066
            if messages.confirm('Executing file', 'Show output'):
926
1067
                lst = [(l, 2) for l in msg.split('\n')]
927
 
                pyview.InternalView('Output of "%s"' % cmd,
928
 
                                    lst, center = 0).run()
 
1068
                pyview.InternalView('Output of "%s"' % encode(cmd),
 
1069
                                    lst, center=0).run()
929
1070
    curses.curs_set(0)
930
1071
    tab.refresh()
931
1072
 
937
1078
        curses.endwin()
938
1079
        if len(tab.selections):
939
1080
            for f in tab.selections:
940
 
                cmd = get_escaped_command(cmd, f)
941
 
                os.system('cd \"%s\"; %s' % (tab.path, cmd))
 
1081
                os.system('cd \"%s\"; %s' % (encode(tab.path),
 
1082
                                             get_escaped_command(cmd, f)))
942
1083
            tab.selections = []
943
1084
        else:
944
 
            cmd = get_escaped_command(cmd, tab.sorted[tab.file_i])
945
 
            os.system('cd \"%s\"; %s' % (tab.path, cmd))
 
1085
            os.system('cd \"%s\"; %s' % (encode(tab.path),
 
1086
                                         get_escaped_command(cmd, tab.sorted[tab.file_i])))
946
1087
        curses.curs_set(0)
947
1088
        tab.refresh()
948
1089
 
954
1095
        from time import ctime
955
1096
 
956
1097
        fullfilename = os.path.join(tab.path, file)
957
 
        file_data = tab.files[file]
958
 
        file_data2 = os.lstat(fullfilename)
 
1098
        fd = tab.files[file]
 
1099
        fde = files.get_fileinfo_extended(fullfilename)
959
1100
        buf = []
960
1101
        user = os.environ['USER']
961
1102
        username = files.get_user_fullname(user)
963
1104
        buf.append(('%s v%s executed by %s' % (LFM_NAME, VERSION, username), 5))
964
1105
        buf.append(('<%s@%s> on a %s %s [%s]' % (user, host, so, ver, arch), 5))
965
1106
        buf.append(('', 2))
966
 
        cmd = get_escaped_command('file', fullfilename)
967
 
        fileinfo = os.popen(cmd).read().split(':')[1].strip()
968
 
        buf.append(('%s: %s (%s)' % (files.FILETYPES[file_data[0]][1], file,
 
1107
        cmd = get_escaped_command('file -b', fullfilename)
 
1108
        fileinfo = get_shell_output2(cmd)
 
1109
        if fileinfo is None:
 
1110
            fileinfo = 'no type information'
 
1111
        buf.append(('%s: %s (%s)' % (files.FILETYPES[fd[0]][1], encode(file),
969
1112
                                     fileinfo), 6))
970
1113
        if not tab.vfs:
971
1114
            path = tab.path
972
1115
        else:
973
1116
            path = vfs.join(tab) + ' [%s]' % tab.base
974
 
        buf.append(('Path: %s' % path[-(curses.COLS-8):], 6))
975
 
        buf.append(('Size: %s bytes' % file_data[files.FT_SIZE], 6))
 
1117
        buf.append(('Path: %s' % encode(path[-(curses.COLS-8):]), 6))
 
1118
        buf.append(('Size: %s bytes' % fd[files.FT_SIZE], 6))
976
1119
        buf.append(('Mode: %s (%4.4o)' % \
977
 
                    (files.perms2str(file_data[files.FT_PERMS]),
978
 
                     file_data[files.FT_PERMS]), 6))
979
 
        buf.append(('Links: %s' % file_data2[stat.ST_NLINK], 6))
 
1120
                    (files.perms2str(fd[files.FT_PERMS]),
 
1121
                     fd[files.FT_PERMS]), 6))
 
1122
        buf.append(('Links: %s' % fde[0], 6))
980
1123
        buf.append(('User ID: %s (%s) / Group ID: %s (%s)' % \
981
 
                    (file_data[files.FT_OWNER], file_data2[stat.ST_UID],
982
 
                     file_data[files.FT_GROUP], file_data2[stat.ST_GID]), 6))
983
 
        buf.append(('Last access: %s' % ctime(file_data2[stat.ST_ATIME]), 6))
984
 
        buf.append(('Last modification: %s' % ctime(file_data2[stat.ST_MTIME]), 6))
985
 
        buf.append(('Last change: %s' % ctime(file_data2[stat.ST_CTIME]), 6))
 
1124
                    (fd[files.FT_OWNER], fde[1],
 
1125
                     fd[files.FT_GROUP], fde[2]), 6))
 
1126
        buf.append(('Last access: %s' % ctime(fde[3]), 6))
 
1127
        buf.append(('Last modification: %s' % ctime(fde[4]), 6))
 
1128
        buf.append(('Last change: %s' % ctime(fde[5]), 6))
986
1129
        buf.append(('Location: %d, %d / Inode: #%X (%Xh:%Xh)' % \
987
 
                    ((file_data2[stat.ST_DEV] >> 8) & 0x00FF,
988
 
                    file_data2[stat.ST_DEV] & 0x00FF,
989
 
                    file_data2[stat.ST_INO], file_data2[stat.ST_DEV],
990
 
                    file_data2[stat.ST_INO]), 6))
991
 
        fss = files.get_fs_info()
992
 
        fs = ['/', '0', '0', '0', '0%', '/', 'unknown']
993
 
        for e in fss:
994
 
            if fullfilename.find(e[5]) != -1 and (len(e[5]) > len(fs[5]) or e[5] == os.sep):
995
 
                fs = e
996
 
        buf.append(('File system: %s on %s (%s) %d%% free' % \
997
 
                    (fs[0], fs[5], fs[6], 100 - int(fs[4][:-1])), 6))
998
 
        pyview.InternalView('Information about \'%s\'' % file, buf).run()
 
1130
                    ((fde[6] >> 8) & 0x00FF, fde[6] & 0x00FF,
 
1131
                     fde[7], fde[6], fde[7]), 6))
 
1132
        mountpoint, device, fstype = files.get_mountpoint_for_file(fullfilename)
 
1133
        buf.append(('File system: %s on %s (%s)' % \
 
1134
                        (device, mountpoint, fstype), 6))
 
1135
        pyview.InternalView('Information about \'%s\'' % encode(file),  buf).run()
999
1136
 
1000
1137
    if tab.selections:
1001
1138
        for f in tab.selections:
1006
1143
 
1007
1144
 
1008
1145
# change permissions
1009
 
def __do_change_perms(filename, ret):
1010
 
    ans = files.set_perms(filename, ret[0])
1011
 
    if ans:
1012
 
        messages.error('Chmod', '%s (%s)' % (ans, filename))
1013
 
    ans = files.set_owner_group(filename, ret[1], ret[2])
1014
 
    if ans:
1015
 
        messages.error('Chown', '%s (%s)' % (ans, filename))
 
1146
def __do_change_perms(filename, perms, owner, group, recursive):
 
1147
    try:
 
1148
        ans = files.set_perms(filename, perms, recursive)
 
1149
        if ans:
 
1150
            messages.error('Chmod "%s"' % filename, '%s (%s)' % ans)
 
1151
        ans = files.set_owner_group(filename, owner, group, recursive)
 
1152
        if ans:
 
1153
            messages.error('Chown "%s"' % filename, '%s (%s)' % ans)
 
1154
    except UnicodeError:
 
1155
        app.display()
 
1156
        messages.error('Change permissions',
 
1157
                       'Files with invalid encoding, convert first')
 
1158
 
1016
1159
 
1017
1160
def do_change_perms(tab):
1018
1161
    if tab.selections:
1019
 
        change_all = 0
 
1162
        change_all = False
1020
1163
        for i, f in enumerate(tab.selections):
1021
1164
            if not change_all:
1022
1165
                ret = messages.ChangePerms(f, tab.files[f], i+1,
1025
1168
                    break
1026
1169
                elif ret == 0:
1027
1170
                    continue
1028
 
                elif ret[3] == 1:
1029
 
                    change_all = 1
 
1171
                elif ret[4] == True:
 
1172
                    change_all = True
1030
1173
            filename = os.path.join(tab.path, f)
1031
 
            __do_change_perms(filename, ret)
 
1174
            __do_change_perms(filename, *ret[:-1])
1032
1175
        tab.selections = []
1033
1176
    else:
1034
1177
        filename = tab.get_file()
1038
1181
        if ret == -1:
1039
1182
            return
1040
1183
        filename = os.path.join(tab.path, filename)
1041
 
        __do_change_perms(filename, ret)
 
1184
        __do_change_perms(filename, *ret[:-1])
1042
1185
    app.regenerate()
1043
1186
 
1044
1187
 
1045
1188
# do show filesystems info
1046
1189
def do_show_fs_info():
1047
 
    """Show file systems info"""
1048
 
 
1049
 
    fs = files.get_fs_info()
1050
 
    if type(fs) != type([]):
1051
 
        messages.error('Show filesystems info', fs)
1052
 
        return
 
1190
    try:
 
1191
        fs = get_shell_output('df -h')
 
1192
    except (IOError, os.error), (errno, strerror):
 
1193
        messages.error('Show filesystems info', (strerror, errno))
 
1194
        return
 
1195
    if fs is None or fs == '':
 
1196
        messages.error('Show filesystems info', ('Can\'t run "df" command', 0))
 
1197
        return
 
1198
    fs = fs.split('\n')
1053
1199
    buf = []
1054
 
    buf.append(('Filesystem       FS type    Total Mb     Used   Avail.  Use%  Mount point', 6))
1055
 
    buf.append('-')
1056
 
    for l in fs:
1057
 
        buf.append(('%-15s  %-10s  %7s  %7s  %7s  %4s  %s' % \
1058
 
                    (l[0], l[6], l[1], l[2], l[3], l[4], l[5]), 2))
1059
 
    texts = [l[0] for l in buf]
1060
 
    buf[1] = ('-' * len(max(texts)), 6)
 
1200
    buf.append((fs[0].strip(), 6))
 
1201
    buf.append(('-'*len(fs[0]), 6))
 
1202
    for l in fs[1:]:
 
1203
        buf.append((l.strip(), 2))
1061
1204
    pyview.InternalView('Show filesystems info', buf).run()
1062
1205
 
1063
1206
 
1066
1209
    # ask data
1067
1210
    fs, pat = doDoubleEntry(tab.path, 'Find files', 'Filename', '*', 
1068
1211
                            'Content', '', with_complete2=False)
1069
 
    if fs == None or fs == '':
 
1212
    if fs is None or fs == '':
1070
1213
        return
1071
1214
    path = os.path.dirname(fs)
1072
1215
    fs = os.path.basename(fs)
1073
 
    if path == None or path == '':
 
1216
    if path is None or path == '':
1074
1217
        path = tab.path
1075
1218
    if path[0] != os.sep:
1076
1219
        path = os.path.join(tab.path, path)
1134
1277
                curses.curs_set(0)
1135
1278
                curses.endwin()
1136
1279
                os.system('%s +%d \"%s\"' %  (app.prefs.progs['pager'],
1137
 
                                              line,  get_escaped_filename(f)))
 
1280
                                              line, get_escaped_filename(f)))
1138
1281
                curses.curs_set(0)
1139
1282
            else:
1140
1283
                messages.error('View', 'it\'s a directory',
1156
1299
            cmd2 = doEntry(tab.path, 'Do something on file', 'Enter command')
1157
1300
            if cmd2:
1158
1301
                curses.endwin()
1159
 
                os.system('%s \"%s\"' % (cmd2, get_escaped_filename(f)))
 
1302
                os.system(get_escaped_command(cmd2, f))
1160
1303
                curses.curs_set(0)
1161
1304
                app.regenerate()
1162
1305
        else:
1169
1312
    while True:
1170
1313
        path = messages.Entry(title, help, path, with_historic, with_complete,
1171
1314
                              tabpath).run()
1172
 
        if type(path) == type([]):
 
1315
        if isinstance(path, list):
1173
1316
            path = path.pop()
1174
1317
        else:
1175
1318
            return path
1185
1328
                                    help2, path2,
1186
1329
                                    with_historic2, with_complete2, tabpath2,
1187
1330
                                    active_entry=0).run()
1188
 
        if type(path) != type([]):
 
1331
        if not isinstance(path, list):
1189
1332
            return path
1190
1333
        else:
1191
1334
            active_entry = path.pop()
1198
1341
class Tree(object):
1199
1342
    """Tree class"""
1200
1343
 
1201
 
    def __init__(self, path = os.sep, panemode = 0):
 
1344
    def __init__(self, path=os.sep, panemode=0):
1202
1345
        if not os.path.exists(path):
1203
1346
            raise ValueError, 'path does not exist'
1204
1347
        self.panemode = panemode
1219
1362
                      if os.path.isdir(os.path.join(path, d))]
1220
1363
        except OSError:
1221
1364
            pass
 
1365
        if not app.prefs.options['show_dotfiles']:
 
1366
            ds = [d for d in ds if d[0] != '.']
1222
1367
        ds.sort()
1223
1368
        return ds
1224
1369
 
1254
1399
            if d == expanded_node:
1255
1400
                lst2.append([d, i, os.path.join(base, d)])
1256
1401
                lst3 = self.__get_node(i+1, tn, td, os.path.join(base, d))
1257
 
                if lst3 != None:
 
1402
                if lst3 is not None:
1258
1403
                    lst2.extend(lst3)
1259
1404
            else:
1260
1405
                lst2.append([d, i, os.path.join(base, d)])
1298
1443
            if fullname == self.path:
1299
1444
                name += ' <====='
1300
1445
            if name == os.sep:
1301
 
                print ' ' + name
 
1446
                print encode(' ' + name)
1302
1447
            else:
1303
 
                print ' | ' * depth + ' +- ' + name
 
1448
                print encode(' | ' * depth + ' +- ' + name)
1304
1449
 
1305
1450
 
1306
1451
    # GUI functions
1367
1512
            w = int(app.maxw / 2) - 2
1368
1513
            wd = 3 * depth + 4
1369
1514
            if fullname == self.path:
1370
 
                self.win.addstr(name[:w-wd-3], curses.color_pair(3))
 
1515
                self.win.addstr(encode(name[:w-wd-3]), curses.color_pair(3))
1371
1516
                child_dirs = self.__get_dirs(self.path)
1372
1517
                if len(child_dirs) > 0:
1373
1518
                    self.win.addstr(' ')
1374
1519
                    self.win.addch(curses.ACS_HLINE)
1375
1520
                    self.win.addch(curses.ACS_RARROW)
1376
1521
            else:
1377
 
                self.win.addstr(name[:w-wd])
 
1522
                self.win.addstr(encode(name[:w-wd]))
1378
1523
        # scrollbar
1379
1524
        if n > h:
1380
1525
            nn = max(int(h*h/n), 1)
1398
1543
            path = self.path[:int(wp/2) -1] + '~' + self.path[-int(wp/2):]
1399
1544
        else:
1400
1545
            path = self.path
1401
 
        app.statusbar.win.addstr(' Path: %s' % path)
 
1546
        app.statusbar.win.addstr(' Path: %s' % encode(path))
1402
1547
        app.statusbar.win.refresh()
1403
1548
 
1404
1549
 
1431
1576
                    continue
1432
1577
                newpos = self.pos + 1
1433
1578
            # page previous
1434
 
            elif ch in (curses.KEY_PPAGE, curses.KEY_BACKSPACE,
1435
 
                        0x08, 0x02):                         # BackSpace, Ctrl-B
 
1579
            elif ch in (curses.KEY_PPAGE, curses.KEY_BACKSPACE, 0x02):
 
1580
                # BackSpace, Ctrl-B
1436
1581
                depth = self.tree[self.pos][1]
1437
1582
                if self.pos - (app.maxh-4) >= 0:
1438
1583
                    if depth  == self.tree[self.pos - (app.maxh-4)][1]:
1471
1616
                        newpos += 1
1472
1617
            # home
1473
1618
            elif (ch in (curses.KEY_HOME, 0x01)) or \
1474
 
                 (chext == 1) and (ch == 72):  # home
 
1619
                 (chext == 1) and (ch == 72):  # home, Ctrl-A
1475
1620
                newpos = 1
1476
1621
            # end
1477
1622
            elif (ch in (curses.KEY_END, 0x05)) or \
1478
 
                 (chext == 1) and (ch == 70):   # end
 
1623
                 (chext == 1) and (ch == 70):   # end, Ctrl-E
1479
1624
                newpos = len(self.tree) - 1
1480
1625
            # cursor left
1481
1626
            elif ch == curses.KEY_LEFT:
1505
1650
                self.win.resize(self.dims[0], self.dims[1])
1506
1651
                self.win.mvwin(self.dims[2], self.dims[3])
1507
1652
                continue
 
1653
            # toggle .dot-files
 
1654
            elif ch == 0x08:    # Ctrl-H
 
1655
                toggle_dotfiles(None)
 
1656
                if self.pos != 0 and os.path.basename(self.path)[0] == '.':
 
1657
                    newdepth = self.tree[self.pos][1] - 1
 
1658
                    for i in xrange(self.pos-1, -1, -1):
 
1659
                        if self.tree[i][1] == newdepth:
 
1660
                            break
 
1661
                    newpos = i
 
1662
                else:
 
1663
                    newpos = self.pos
1508
1664
            # quit
1509
1665
            elif ch in (ord('q'), ord('Q'), curses.KEY_F10, 0x03):  # Ctrl-C
1510
1666
                return -1
1511
 
 
1512
1667
            # else
1513
1668
            else:
1514
1669
                continue