123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import json
- import config
- import os
- import sys
- class _PadManager:
- def __init__(self):
- self.pads={}
- self.list=[]
- for file in os.listdir(config.PAD_DIRECTORY):
- if file.lower().endswith(".json") or file.lower().endswith(".conf"):
- x=self.test_pad(file)
- if x:
- self.pads[x] = file
- self.list.append(x)
- def test_pad(self, file):
- name = None
- try:
- with open(os.path.join(config.PAD_DIRECTORY, file)) as f:
- content=f.read()
- x=json.loads(content)
- if x and "name" in x and x["name"]:
- return x["name"]
- except:
- pass
- return None
- def read_pad(self, padname):
- file=os.path.join(config.PAD_DIRECTORY, self.pads[padname])
- with open(file) as f:
- return json.loads(f.read())
- class PadManager:
- __pm = _PadManager()
- @staticmethod
- def read_pad(name):
- return PadManager.__pm.read_pad(name)
- @staticmethod
- def pad_list():
- return PadManager.__pm.list
|