Skip to content

Commit 64c1727

Browse files
committed
Merge pull request #107 from facebook/addCleanMode
Resolves #103 add --clean mode
2 parents dca499e + 45302a6 commit 64c1727

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/processInput.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import stateFiles
1818
from formattedText import FormattedText
1919
from usageStrings import USAGE_STR
20+
from screenFlags import ScreenFlags
2021

2122

2223
def getLineObjs():
@@ -57,6 +58,15 @@ def usage():
5758

5859

5960
if __name__ == '__main__':
61+
flags = ScreenFlags.initFromArgs(sys.argv[1:])
62+
if (flags.getIsCleanMode()):
63+
print('Cleaning out state files...')
64+
for filePath in stateFiles.getAllStateFiles():
65+
if os.path.isfile(filePath):
66+
os.remove(filePath)
67+
print('Done! Removed %d files ' % len(stateFiles.getAllStateFiles()))
68+
sys.exit(0)
69+
6070
if sys.stdin.isatty():
6171
if os.path.isfile(stateFiles.getPickleFilePath()):
6272
print('Using old result...')

src/screenFlags.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,26 @@ def getIsRecordMode(self):
3636
def getPresetCommand(self):
3737
return ' '.join(self.args.command)
3838

39+
def getIsCleanMode(self):
40+
return self.args.clean
41+
3942
@staticmethod
4043
def getArgParser():
4144
parser = argparse.ArgumentParser(prog='fpp')
4245
parser.add_argument('-r',
4346
'--record',
44-
help='''record input and output. This is
47+
help='''
48+
Record input and output. This is
4549
largely used for testing, but you may find it useful for scripting.''',
4650
default=False,
4751
action='store_true')
52+
parser.add_argument('--clean',
53+
default=False,
54+
action='store_true',
55+
help='''
56+
Remove the state files that fpp uses when starting up, including
57+
the previous input used and selection pickle. Useful when using fpp
58+
in a script context where the previous state should be discarded.''')
4859
parser.add_argument('-ko',
4960
'--keep-open',
5061
default=False,

src/stateFiles.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ def getScriptOutputFilePath():
4545
def getLoggerFilePath():
4646
assertDirCreated()
4747
return os.path.expanduser(os.path.join(FPP_DIR, LOGGER_FILE))
48+
49+
50+
def getAllStateFiles():
51+
# keep this update to date! We do not include
52+
# the script output path since that gets cleaned automatically
53+
return [
54+
getPickleFilePath(),
55+
getSelectionFilePath(),
56+
getLoggerFilePath(),
57+
getScriptOutputFilePath(),
58+
]

0 commit comments

Comments
 (0)