| | | |
| 1 | 1 | | #! /usr/bin/env python |
| 2 | 2 | | # |
| 3 | 3 | | # A obpipemenu script for viewing a dir |
| 4 | 4 | | # with a few options |
| 5 | 5 | | # |
| 7 | 7 | | import sys |
| 8 | 8 | | import os |
| 10 | 10 | | ### |
| 11 | 11 | | # Global Variables |
| 12 | 12 | | ### |
| 14 | | - | DIRPRG = "thunar" #Program to open directories |
| 15 | 14 | | VIDPRG = "vlc" #Program to open files |
| 16 | | - | #Finish types implementation |
| 17 | | - | VIDTYPES = ( "avi", "mpg", "mkv", "m4v", "flv", ) |
| 18 | 15 | | PYPIPE = str(os.path.abspath(__file__)) + " " |
| 21 | 18 | | def recent_file_list(src): |
| 22 | 19 | | files = [] |
| 23 | 20 | | os.chdir(src) |
| 24 | 21 | | # Get a list of tuples of filenames and their times modified. |
| 25 | 22 | | for fn in os.listdir(src): |
| 26 | 23 | | mtime = os.path.getmtime(os.path.abspath(fn)) |
| 27 | 24 | | timename = mtime, fn |
| 28 | 25 | | files.append(timename) |
| 29 | 26 | | # Sort the list by times, newest first |
| 30 | 27 | | recenttuples = sorted(files, reverse=True) |
| 31 | 28 | | # Get the names only, ina new list |
| 32 | 29 | | recents = [ t[1] for t in recenttuples ] |
| 33 | 30 | | return recents |
| 35 | 32 | | def printing(recents): |
| 36 | 33 | | for f in recents: |
| 37 | 34 | | if os.path.isdir(os.path.abspath(f)): |
| 38 | 35 | | print_dir(f,PYPIPE) |
| 39 | 36 | | else: |
| 40 | 37 | | print_file(f,VIDPRG) |
| 42 | 39 | | def print_file(fn,prg): |
| 43 | 40 | | print '<item label="%s...">' % fn[:20] |
| 44 | 41 | | print '\t<action name="Execute">' |
| 45 | 42 | | print "\t\t<execute>%s '%s' </execute>" % (prg, os.path.abspath(fn)) |
| 46 | 43 | | print '\t</action>' |
| 47 | 44 | | print '</item>' |
| 49 | 46 | | def print_dir(src,pypipe): |
| 50 | 47 | | print '<menu id="%s" label="%s..." execute="%s" />' % (src[:20], |
| 51 | 48 | | src[:20],pypipe + os.path.abspath(src)) |
| 52 | 49 | | def main(): |
| 54 | 51 | | src = os.path.abspath(sys.argv[1]) |
| 55 | 52 | | recents = recent_file_list(src) |
| 56 | 53 | | print "<openbox_pipe_menu>" |
| 57 | 54 | | printing(recents) |
| 58 | 55 | | print "</openbox_pipe_menu>" |
| 60 | 57 | | if __name__ == '__main__': |
| 61 | 58 | | main() |