CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by jmeb on Thu 14th Jul 18:35 (modification of post by view diff)
View followups from jmeb | download | new post

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

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me