Browse Source

subprocess replacing system

bugfixes
harshadyeola 10 years ago
parent
commit
47f1c5e145
  1. 22
      ee/core/fileutils.py
  2. 52
      ee/core/services.py
  3. 8
      ee/core/shellexec.py

22
ee/core/fileutils.py

@ -10,16 +10,16 @@ class EEFileUtils():
def remove(filelist): def remove(filelist):
for file in filelist: for file in filelist:
if os.path.isfile(file): if os.path.isfile(file):
print("Removing "+os.path.basename(file)+" ...")
os.remove(file)
print("Done")
if os.path.isdir(file):
try:
print("Removing "+os.path.basename(file)+" ...") print("Removing "+os.path.basename(file)+" ...")
os.remove(file) shutil.rmtree(file)
print("Done") print("Done")
if os.path.isdir(file): except shutil.Error as e:
try: print("Unable to remove file, [{err}]"
print("Removing "+os.path.basename(file)+" ...") .format(err=str(e.reason)))
shutil.rmtree(file) return False
print("Done")
except shutil.Error as e:
print("Unable to remove file, [{err}]"
.format(err=str(e.reason)))
return False

52
ee/core/services.py

@ -1,4 +1,8 @@
"""EasyEngine service start/stop/restart module.""" """EasyEngine service start/stop/restart module."""
import os
import sys
import subprocess
from subprocess import Popen
class EEService(): class EEService():
@ -6,3 +10,51 @@ class EEService():
def ___init__(): def ___init__():
# TODO method for services # TODO method for services
pass pass
def start_service(service_name):
try:
retcode = subprocess.getstatusoutput('service {0} start'
.format(service_name))
if retcode[0] == 0:
print("Started : {0}".format(service_name))
else:
print(retcode[1])
except OSError as e:
print("Execution failed:", e)
return False
def stop_service(service_name):
try:
retcode = subprocess.getstatusoutput('service {0} stop'
.format(service_name))
if retcode[0] == 0:
print("Stopped : {0}".format(service_name))
return True
else:
return False
except OSError as e:
print("Execution failed:", e)
return False
def restart_service(service_name):
try:
stop_service(service_name)
start_service(service_name)
except OSError as e:
print("Execution failed:", e)
def get_service_status(service_name):
try:
is_exist = subprocess.getstatusoutput('which {0}'
.format(service_name))[0]
if is_exist == 0:
retcode = subprocess.getstatusoutput('service {0} status'
.format(service_name))
if retcode[0] == 0:
return True
else:
return False
else:
return False
except OSError as e:
return False

8
ee/core/shellexec.py

@ -1,5 +1,8 @@
"""EasyEngine shell executaion functions.""" """EasyEngine shell executaion functions."""
import os import os
import sys
import subprocess
from subprocess import Popen
class EEShellExec(): class EEShellExec():
@ -8,4 +11,7 @@ class EEShellExec():
pass pass
def cmd_exec(command): def cmd_exec(command):
os.system(command) try:
retcode = subprocess.getstatusoutput(command)
except OSError as e:
print(e)

Loading…
Cancel
Save