| | #!/usr//bin/env python |
---|
| | #!/usr//bin/env python2 |
---|
| | """ |
---|
| | tdir - Display Formatted Directory Listings |
---|
| | Copyright (c) 2001-2014 TundraWare Inc., All Rights Reserved. |
---|
| | """ |
---|
| |
---|
| | os.close(fd) |
---|
| | |
---|
| | except: |
---|
| | pass |
---|
| | |
---|
| | |
---|
| | if not cr: |
---|
| | cr = (env.get('LINES', 25), env.get('COLUMNS', 80)) |
---|
| | |
---|
| | ### Use get(key[, default]) instead of a try/catch |
---|
| | #try: |
---|
| | # cr = (env['LINES'], env['COLUMNS']) |
---|
| | #except: |
---|
| | # cr = (25, 80) |
---|
| | |
---|
| | |
---|
| | return int(cr[1]), int(cr[0]) |
---|
| | |
---|
| | # End of 'GetTerminalSize()' |
---|
| | |
---|
| |
---|
| | else: # File has no extension |
---|
| | ext = "" |
---|
| | name = x |
---|
| | ExtList[ext].append(name) |
---|
| | |
---|
| | |
---|
| | return ExtList |
---|
| | |
---|
| | |
---|
| | def OutputColumns(list, ISDIRLIST): |
---|
| |
---|
| | sys.stdout.write(INDENT * PAD) |
---|
| | sys.stdout.write(x + (COLWIDTH - len(x)) * PAD) |
---|
| | col += 1 |
---|
| | sys.stdout.write("\n\n") |
---|
| | |
---|
| | |
---|
| | |
---|
| | def DisplayOutput(dir, DirList, FileList): |
---|
| | if (dir[-1] != "/") and (dir[-1] != "\\"): |
---|
| | DIREND = "/\n" |
---|
| |
---|
| | |
---|
| | else: |
---|
| | FileList.sort() |
---|
| | OutputColumns(FileList, False) |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | def BuildFileList (args, dir, files): |
---|
| | DirList = [] |
---|
| | FileList = [] |
---|
| | for x in files: |
---|
| |
---|
| | DisplayOutput(dir, DirList, FileList) |
---|
| | |
---|
| | |
---|
| | def Usage(): |
---|
| | UsageInfo = ( |
---|
| | UsageInfo = ( |
---|
| | ("tdir " + VERSION.split()[2] + |
---|
| | " - Copyright (c) 2001-2014 TundraWare Inc., All Rights Reserved. \n", ""), |
---|
| | (" usage: tdir [-DRdefhtv] [-c #] [-s c] [-w #] [dir...] where,\n\n", ""), |
---|
| | ("-D", "Do not display dot files\n"), |
---|
| |
---|
| | opts, args = getopt.getopt(sys.argv[1:], '-DRc:edfhs:tvw:') |
---|
| | except getopt.GetoptError: |
---|
| | Usage() |
---|
| | sys.exit(2) |
---|
| | |
---|
| | |
---|
| | for opt, val in opts: |
---|
| | if opt == "-D": |
---|
| | SHOWDOT = False |
---|
| | if opt == "-R": |
---|
| |
---|
| | |
---|
| | if OWIDTH < COLWIDTH: |
---|
| | sys.stdout.write("Huh? Column width exceeds output width!\n") |
---|
| | sys.exit(2) |
---|
| | |
---|
| | |
---|
| | TWIDTH = COLWIDTH - 1 # Text width |
---|
| | MAXCOL, INDENT = divmod(OWIDTH, COLWIDTH) # No of output cols & indent |
---|
| | |
---|
| | if len(args) == 0: # Default to local directory if none given |
---|
| |
---|
| | |
---|
| | for root in args: |
---|
| | if not os.path.isdir(root): |
---|
| | sys.stdout.write(root + " is not a directory!\n") |
---|
| | sys.exit(2) |
---|
| | sys.exit(2) |
---|
| | if RECURSE: |
---|
| | os.path.walk(root, BuildFileList, None) |
---|
| | else: |
---|
| | BuildFileList(None, root, os.listdir(root)) |
---|
| | |