import os
import random
import sys
+import time
print_to_stderr = False
+random.seed(os.getpid() + int(time.time()))
+
+file_name = None
if (len(sys.argv) == 1):
- pass
+ allfiles = []
+ for root, dirs, files in os.walk("."):
+ for f in files:
+ allfiles.append(os.path.join(root, f))
+ if (len(allfiles) == 0):
+ sys.exit(1)
+ r = random.randint(0,len(allfiles) - 1)
+ file_name = allfiles[r]
elif (len(sys.argv) == 2) and (sys.argv[1] == "-S"):
print_to_stderr = True
else:
- print >>sys.stderr, "invalid command-line arguments"
- sys.exit(1)
-
-allfiles = []
+ allfiles = sys.argv[1:]
+ r = random.randint(0,len(allfiles) - 1)
+ file_name = allfiles[r]
-for root, dirs, files in os.walk("."):
- for f in files:
- allfiles.append(os.path.join(root, f))
-if (len(allfiles) == 0):
- sys.exit(1)
-random.seed(os.getpid())
-r = random.randint(0,len(allfiles) - 1)
-print(allfiles[r])
+print(file_name)
if (print_to_stderr):
- print >>sys.stderr, (allfiles[r])
+ print >>sys.stderr, file_name
sys.exit(0)