home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 October - Disc 3 / PCNET_CD_2006_10_3.iso / apps / ShutterflyStudioInstaller_ext.exe / Scripts / run_any_script.py < prev    next >
Encoding:
Python Source  |  2005-02-20  |  1.2 KB  |  65 lines

  1. do_again = 1;
  2.  
  3. dir_choice = "../Scripts"
  4.  
  5.  
  6. import string
  7. import re
  8. import os
  9. import traceback
  10. import sys
  11. from os.path import join, getsize
  12. files = [];
  13.  
  14. #sys.path.append("..\Scripts")
  15. #sys.path.append("..\Lib")
  16.  
  17. while(do_again) :
  18.  
  19.     i = 0
  20.     scripts = []
  21.  
  22.     root = dir_choice
  23.     if(len(files) < 1) :
  24.         files = os.listdir(dir_choice)
  25.  
  26.     for name in files:
  27.             # if it ends in .JPG
  28.             if (re.search("\.py\Z", string.lower(name)) > -1) :
  29.                 full_path = os.path.join(root, name) 
  30.  
  31.                 scripts.append(full_path);
  32.  
  33.                 print i, ") ", name
  34.                 i = i + 1
  35.  
  36.  
  37.  
  38.     print "r) Enter script name"
  39.     print "\nChoice >>>",
  40.  
  41.     choice = raw_input();
  42.  
  43.     if(choice != "") :
  44.         if(choice.isalpha()) :
  45.             if(choice.lower == "r") :
  46.                 print "Enter a script to run >>> ",
  47.                 script_name = raw_input();
  48.             else :
  49.                 script_name = "";
  50.         else :
  51.             script_name = scripts[int(choice)]
  52.  
  53.         if(script_name and script_name != ""):
  54.             try:
  55.                 execfile(script_name)
  56.             except:
  57.                 print "Exception raised during script run:"
  58.                 print traceback.print_exc()
  59.  
  60.         print "Would you like to run another script? >>> ",
  61.         choice = raw_input();
  62.  
  63.         if choice != 'y':
  64.             do_again = 0    
  65.