frappy-edit: add default cfg path given typically at psi
Change-Id: I91032c912d76f555ae88e3e7ae313fa3c03948bd
This commit is contained in:
@@ -23,11 +23,13 @@ KEY.add(
|
|||||||
|
|
||||||
VERSION_SEPARATOR = "\n''''"
|
VERSION_SEPARATOR = "\n''''"
|
||||||
TIMESTAMP_FMT = '%Y-%m-%d-%H%M%S'
|
TIMESTAMP_FMT = '%Y-%m-%d-%H%M%S'
|
||||||
|
|
||||||
|
|
||||||
|
def get_timestamp(file):
|
||||||
|
return time.strftime(TIMESTAMP_FMT, time.localtime(file.stat().st_mtime))
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - ctrl-K: on previous versions copy and advance to next module
|
|
||||||
# - use also shift-Tab for level up?
|
# - use also shift-Tab for level up?
|
||||||
# - directory to save to
|
|
||||||
# - remove older versions, for which a newer exist already: a restore removes the older one
|
|
||||||
|
|
||||||
|
|
||||||
def unix_cmd(cmd, *args):
|
def unix_cmd(cmd, *args):
|
||||||
@@ -749,7 +751,14 @@ class EditorMain(Main):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
sections = []
|
sections = []
|
||||||
self.versions = dict((v.split('\n', 1) for v in sections))
|
self.versions = dict((v.split('\n', 1) for v in sections))
|
||||||
|
# the path every change is written to:
|
||||||
self.tmppath = self.version_dir / f'{name}.current'
|
self.tmppath = self.version_dir / f'{name}.current'
|
||||||
|
try:
|
||||||
|
# if a file exists already, add it to the version history
|
||||||
|
filecontent = self.tmppath.read_text()
|
||||||
|
self.add_version(filecontent, get_timestamp(self.tmppath))
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
if cfgpath:
|
if cfgpath:
|
||||||
cfgpaths = [cfgpath]
|
cfgpaths = [cfgpath]
|
||||||
else:
|
else:
|
||||||
@@ -764,7 +773,7 @@ class EditorMain(Main):
|
|||||||
self.cfgpath = cfgpath
|
self.cfgpath = cfgpath
|
||||||
if cfgpath != self.tmppath:
|
if cfgpath != self.tmppath:
|
||||||
self.titlebar.mid = str(cfgpath)
|
self.titlebar.mid = str(cfgpath)
|
||||||
timestamp = time.strftime(TIMESTAMP_FMT, time.localtime(cfgpath.stat().st_mtime))
|
timestamp = get_timestamp(cfgpath)
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
@@ -864,6 +873,13 @@ class EditorMain(Main):
|
|||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
self.save()
|
self.save()
|
||||||
|
try:
|
||||||
|
filecontent = self.cfgpath.read_text()
|
||||||
|
except FileNotFoundError:
|
||||||
|
filecontent = ''
|
||||||
|
if filecontent == self.filecontent:
|
||||||
|
self.log.info('%s was not changed', self.cfgpath)
|
||||||
|
return True
|
||||||
savedialog = SaveDialog(self.cfgpath)
|
savedialog = SaveDialog(self.cfgpath)
|
||||||
if savedialog.execute(self) == KEY.QUIT:
|
if savedialog.execute(self) == KEY.QUIT:
|
||||||
filename = savedialog.filename
|
filename = savedialog.filename
|
||||||
@@ -912,11 +928,21 @@ class EditorMain(Main):
|
|||||||
except Exception:
|
except Exception:
|
||||||
print(formatExtendedTraceback())
|
print(formatExtendedTraceback())
|
||||||
finally:
|
finally:
|
||||||
if self.pidfile:
|
if self.filecontent:
|
||||||
|
# add current content to the version history
|
||||||
|
try:
|
||||||
|
self.add_version(self.filecontent, time.strftime(TIMESTAMP_FMT))
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
if self.tmppath and self.tmppath.exists():
|
||||||
|
# no need to keep the temporary file, as it has been added to the versions
|
||||||
|
self.tmppath.unlink()
|
||||||
|
if self.pidfile and self.pidfile.exists():
|
||||||
self.pidfile.unlink()
|
self.pidfile.unlink()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.environ['FRAPPY_CONFDIR'] = 'cfg:cfg/main:cfg/stick:cfg/addons'
|
# os.environ['FRAPPY_CONFDIR'] = 'cfg:cfg/main:cfg/stick:cfg/addons'
|
||||||
generalConfig.init()
|
generalConfig.init()
|
||||||
|
os.environ['FRAPPY_CONFDIR']
|
||||||
EditorMain(sys.argv[1]).run()
|
EditorMain(sys.argv[1]).run()
|
||||||
|
|||||||
Reference in New Issue
Block a user