clean up
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -10,7 +10,7 @@
|
||||
"request": "launch",
|
||||
"module": "onlyone",
|
||||
"console": "integratedTerminal",
|
||||
"args": ["--configFile","config.yaml"]
|
||||
"args": ["--configFile","config.yaml", "--server"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
defaultProcess: a
|
||||
defaultProcess: nano
|
||||
processes:
|
||||
- key: a
|
||||
cmd: aaa
|
||||
- key: b
|
||||
cmd: aaa
|
||||
- key: cat
|
||||
cmd: cat
|
||||
- key: nano
|
||||
cmd: nano
|
||||
|
||||
@@ -29,7 +29,7 @@ def __killprocesses(killcmds:List, sysprocesses: List):
|
||||
for proc in sysprocesses:
|
||||
if any(" ".join(proc.cmdline()) == x for x in killcmds):
|
||||
proc.kill()
|
||||
log.info("[onlyone][__killprocesses] -> processed kiled : " + proc.name + "(" + proc.id + ")")
|
||||
log.info("[onlyone][__killprocesses] -> processed killed : " + proc.name + "(" + proc.id + ")")
|
||||
return False
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def __forceoneprocessinstance(cmd:str, processes:List):
|
||||
if " ".join(proc.cmdline()) == cmd:
|
||||
if found:
|
||||
proc.kill()
|
||||
log.info("[onlyone][__forceoneprocessinstance] -> processed kiled : " + proc.name + "(" + proc.id + ")")
|
||||
log.info("[onlyone][__forceoneprocessinstance] -> processed killed : " + proc.name + "(" + proc.id + ")")
|
||||
else :
|
||||
found = True
|
||||
if not found:
|
||||
@@ -62,13 +62,13 @@ class Manager:
|
||||
self.__processes=[]
|
||||
self.__current=None
|
||||
|
||||
def load(self, dict:dict):
|
||||
def load(self, dict:dict, loadDefault:bool):
|
||||
if(dict == None):return
|
||||
if("processes" in dict):
|
||||
for p in dict["processes"]:
|
||||
if "key" in p and "cmd" in p:
|
||||
self.addprocess(p["key"], p["cmd"])
|
||||
if("defaultProcess" in dict):
|
||||
if(loadDefault and "defaultProcess" in dict):
|
||||
self.current(dict["defaultProcess"])
|
||||
|
||||
|
||||
|
||||
@@ -15,21 +15,28 @@ logging.basicConfig(level="DEBUG")
|
||||
log = logging.getLogger(__name__)
|
||||
parser = argparse.ArgumentParser(description='onlyone')
|
||||
parser.add_argument('--configFile', type=str, required=False, help='configfile')
|
||||
parser.add_argument('--server', action='store_const', const=True, help='server mode')
|
||||
args = parser.parse_args()
|
||||
|
||||
sys.stdout.write("arguments - " + str(sys.argv))
|
||||
log.info("arguments - " + str(sys.argv))
|
||||
log.info("Current Path:" + os.getcwd())
|
||||
if args.configfile:
|
||||
manager=None
|
||||
if args.configFile:
|
||||
manager = onlyone.Manager()
|
||||
if os.path.isfile(args.configfile):
|
||||
log.info("trying to read file : " + args.configfile)
|
||||
configTxt = open(args.configfile, "r").read()
|
||||
if os.path.isfile(args.configFile):
|
||||
log.info("trying to read file : " + args.configFile)
|
||||
configTxt = open(args.configFile, "r").read()
|
||||
log.info("config file content : " + configTxt)
|
||||
log.info("trying read yaml")
|
||||
configDict = yaml.safe_load(configTxt)
|
||||
manager.load(configDict)
|
||||
|
||||
manager.load(configDict, True)
|
||||
else:
|
||||
log.error("Current Path:" + os.getcwd())
|
||||
log.error("File dont exists:" + args.configfile)
|
||||
|
||||
if args.server:
|
||||
if(manager==None):
|
||||
log.error("server mode selected, but manager not loaded maybe missing --configFile")
|
||||
else:
|
||||
log.info("server loaded...")
|
||||
input("[server mode]")
|
||||
Reference in New Issue
Block a user