#! /usr/bin/env python
#
# A obpipemenu script for viewing a dir
# with a few options
#
import sys
import os
import re
###
# Global Variables
###
EXO = "exo-open" #Opens file with default (XFCE)
XDG = "xdg-open" #Opens file with default (Openbox)
PYPIPE = str(os.path.abspath(__file__)) + " "
def recent_file_list(src):
''' Return a list of full paths for files most recent first '''
files = []
os.chdir(src)
for fn in os.listdir(src):
#Create a tuple (time modified, filename path)
timename = os.path.getmtime(fn), os.path.abspath(fn)
files.append(timename)
# Sort the list by times, newest first
# To sort by oldest first, remove set reverse to False
recenttuples = sorted(files, reverse=True)
# Get the names only, in a new list
recents = []
for t in recenttuples:
#Replace '&'s to avoid openbox xml problems
ampedpath = re.sub(r"&","&",t[1])
recents.append(ampedpath)
return recents
def printing(recents):
''' Decide whether to print a file or menu listing '''
for f in recents:
if os.path.isdir(f):
print_dir(f,PYPIPE)
else:
print_file(f,XDG)
def print_file(fn,prg):
''' Print a listing to open a file '''
print '