You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
574 B
28 lines
574 B
import json
|
|
import os
|
|
|
|
|
|
FILENAME = 'extra-commands.json'
|
|
|
|
|
|
class ExtraCommands(dict):
|
|
|
|
def __init__(self):
|
|
self.last_mtime = 0
|
|
|
|
def reload(self):
|
|
with open(FILENAME) as f:
|
|
commands = json.load(f)
|
|
self.clear()
|
|
self.update(commands)
|
|
|
|
def reload_if_needed(self):
|
|
mtime = os.stat(FILENAME).st_mtime
|
|
if mtime > self.last_mtime:
|
|
self.last_mtime = mtime
|
|
self.reload()
|
|
|
|
def save(self):
|
|
with open(FILENAME, 'w') as f:
|
|
json.dump(self, f, indent=4, sort_keys=True)
|