示例#1
0
文件: ck.py 项目: nlchap0/nlctools
               The  mime type database is a text file of mime types
               and appropriate applications.  It is located in
               $USERGO/mimetypes
ck -           Opens files like above, but filenames are read from a pipe'''

# This program is designed to eliminate the user's need to type in application
# names to open documents.  The program will read the mimetype for the input
# documents (using the command line utility 'file'), look up the appropriate
# application for opening that mimetype, and open the file using the correct
# application.

import os,sys,commands,header

MIMEDATA     = header.mimedata
RECENTDATA   = header.recentdata
MAXDOCLENGTH = header.read_pref('maxdoclength')
MINDOCLENGTH = header.read_pref('mindoclength')

def open_files(mimetypes,docs):
   """Open files given their mimetypes."""
     
   if len(mimetypes) != len(docs):
      print "Number of mimetypes and docs different!"
      sys.exit()

   if os.path.exists(MIMEDATA):
      fp = open(MIMEDATA,"r")
      # read file, ignore anything after a comment character, #, and strip off
      # whitespace and \n chars
      data  = [line.split('#')[0].strip() for line in fp]
      # get rid of empty lines (where # was first char on line) and split by
示例#2
0
文件: lf.py 项目: nlchap0/nlctools
if __name__ == "__main__":
   if '-h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
      print __doc__
      sys.exit()

   nosortchar  = 'ctuvUXS' # ls options which turn off sorting by name
   nosortFlag  = False     # False means to do smart sorting
   altsort     = '-'       # alternative sorting string
   reverseFlag = False     # False means to not reverse the final sorted list
   altlistchar = 'gilhmnoRsx' # ls options that change the default listing
   altlist     = '-'       # - means no alternate listing style will happen
   listAll     = False     # False means no -a or -A option given
   shortFlag   = False     # if True, only first XX files will be printed,
                           # where XX is defined in preferences

   LSARGS = header.read_pref('LsArgs')
   try:
      path = os.getcwd()
   except OSError:
      print "Sorry, but the current folder no longer exists."
      sys.exit()

   if len(path) > 42:
      temp = path[:18] + "..." + path[-18:]
      path = temp

   options = args = ''
   for val in sys.argv[1:]:
      if val[0] == '-':
         options = options + val[1:]
      else:
示例#3
0
      temp = time.strptime(ascdate)
      year = temp[0]
      dayofyear = temp[7]
      diff = 365*(curyear - year) + curdayofyear - dayofyear
      if diff >= old_delete:
         return 1 # older than old_delete
      else:
         return 0 # not old enough

if __name__ == "__main__":
   if '-h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv:
      print __doc__
      sys.exit()

   size = 0
   old_delete = header.read_pref('olddelete') # time in days, to delete files
   filelist = []
   newtrashdata = []
   if len(sys.argv) > 1:
      if sys.argv[1].lower() == 'all':
         old_delete = 0 # Delete All files, regardless of date
      else:
         try:
            old_delete = int(sys.argv[1])
         except ValueError:
            print "### Fatal Error!  Cannot understand number of days: %s" %sys.argv[1]
            sys.exit()

   data = header.read_trash()
   header.make_trash_backup()