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