-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecklist.py
More file actions
executable file
·58 lines (45 loc) · 2.76 KB
/
checklist.py
File metadata and controls
executable file
·58 lines (45 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'''
checklist.py
Copyright 2013 Wohlfe
Licensed under the Apache License v2
This script takes a directory path as an argument, searches it recursively, and outputs the files in a PlainTasks
checklist, except for folder and files that start with a period. Windows can't handle outputting checkboxes, so for now it uses a *.
Yes this requires Python 3. If you can't use 3 just change the print functions, but you really should be using 3.
'''
import os, sys, locale
if sys.version_info < (3, 0): # Checks the Python version
raise "You must use Python 3 or change the script."
try:
rootdir = sys.argv[1].rstrip() #Expects an argument, strips whitespace from it.
except IndexError:
print("This script requires a path to run on.")
def checklist(rootdir):
filenames = []
outfileName = os.path.join(rootdir, "checklist.tasks") #Creates the output file in the directory
print("Folders searched:") #Python 2 = print "Folders searched:"
for root, subFolders, files in os.walk(rootdir):
with open(outfileName, 'w') as fileOut:
if sys.platform.startswith('windows'):
fileOut.write("Replace the * with checkboxes. Remember, the script excludes folders \
and files that start with a period. \n")
else:
fileOut.write("Remember, the script excludes folders and files that start with a period. \n")
for folder in subFolders:
if folder.find('.') != -1 or root.find('.') != -1: #Checks if the folder name has a period, drops it if so.
subFolders.remove(folder)
print("Ignoring %s." % (folder))
else:
print("Checking %s." % os.path.join(root, folder)) #Python 2 = print os.path.join(root, folder)
for filename in files:
if filename[0] == '.': #Checks if the file name starts with a period, drops it if so.
files.remove(filename)
else:
filenames.append(os.path.join(root, filename))
for filename in filenames:
short_filename = filename[len(rootdir):] #Shortens the output, don't need the entire directory on every line.
if sys.platform.startswith('windows'):
fileOut.write("*" + " %s \n" % short_filename) #If everything check out, this writes it to the file with a * instead of a checkbox.
else:
fileOut.write(chr(9744) + " %s \n" % short_filename) #If everything check out, this writes it to the file with a checkbox.
print("Completed. The output file is %s" % outfileName) #Python 2 = print "Completed. The output file is " + outfileName
checklist(rootdir)