File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717import stateFiles
1818from formattedText import FormattedText
1919from usageStrings import USAGE_STR
20+ from screenFlags import ScreenFlags
2021
2122
2223def getLineObjs ():
@@ -57,6 +58,15 @@ def usage():
5758
5859
5960if __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...' )
Original file line number Diff line number Diff 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
4549largely 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 ,
Original file line number Diff line number Diff line change @@ -45,3 +45,14 @@ def getScriptOutputFilePath():
4545def 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+ ]
You can’t perform that action at this time.
0 commit comments