Commits

Sven Grunewaldt  committed 85969e6

More code cleanup

  • Participants
  • Parent commits c627a0b

Comments (0)

Files changed (5)

 #!/usr/bin/python3
 # coding=utf-8
-import os
 from services import Nginx, PHP, MongoDB
 import tools
 import settings
 if settings.START_MONGODB:
     print("MongoDB version: {}".format(mongodb))
 
-print('')
+print("")
 
 stop_execution = False
 
 
 print("")
 print("Menu:")
-print("(STRG+c) or (q) to quit")
 if settings.START_NGINX:
-    print("(r) to reload nginx config")
+    print("(r) to reload Nginx config")
 if settings.START_PHP:
-    print("(p) to restart php processes")
+    print("(p) to restart PHP processes")
+print("---")
+print("(STRG+c) or (q) to quit")
 print("")
 
 while True:
     if char == b"\x03" or char == b"q":
         break
     elif char == b"r" and settings.START_NGINX:
-        print("Reloading nginx config... ",end="")
+        print("Reloading Nginx config... ",end="")
         nginx.reload_config()
         print("done")
     elif char == b"p" and settings.START_PHP:
-        print("Restarting php processes... ",end="")
+        print("Restarting PHP processes... ",end="")
         php.stop()
         php.start()
         print("done")

File services/MongoDB.py

 # coding=utf-8
 import subprocess
 import os
-import ctypes
 import settings
 
 class MongoDB(object):
     def start(self):
         with open(os.devnull, "w") as fnull:
             self.process = subprocess.Popen(
-                args = [self.executable, '--config', self.config_path],
+                args = [self.executable, "--config", self.config_path],
                 cwd = self.path,
                 stdout = fnull
             )
     def stop(self,):
         with open(os.devnull, "w") as fnull:
             stop_process = subprocess.Popen(
-                args = [self.client_executable, 'localhost/admin', '--eval', 'db.shutdownServer();'],
+                args = [self.client_executable, "localhost/admin", "--eval", "db.shutdownServer();"],
                 cwd = self.path,
                 stdout = fnull
             )
             stop_process.wait()
 
     def __str__(self):
-        args = [self.executable, '--config', self.config_path, '--version']
+        args = [self.executable, "--config", self.config_path, "--version"]
 
         proc = subprocess.Popen(args=args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout, stderr = proc.communicate()
 
-        return ", ".join(stdout.strip().decode('utf-8').splitlines())
+        return ", ".join(stdout.strip().decode("utf-8").splitlines())

File services/Nginx.py

         if settings.START_PHP:
             self.parse_upstreams()
 
-            if not self.upstreams.__contains__('php'):
+            if not self.upstreams.__contains__("php"):
                 sys.exit("Could not find upstream php in nginx config")
 
     def start(self):
 
     def stop(self,):
         stop_process = subprocess.Popen(
-            args = [self.executable, '-s', 'quit'],
+            args = [self.executable, "-s", "quit"],
             cwd = self.path
         )
 
 
     def reload_config(self):
         reload_process = subprocess.Popen(
-            args = [self.executable, '-s', 'reload'],
+            args = [self.executable, "-s", "reload"],
             cwd = self.path
         )
 
         proc = subprocess.Popen(args=args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout, stderr = proc.communicate()
 
-        stderr = stderr.replace(b'nginx version: ', b'')
+        stderr = stderr.replace(b"nginx version: ", b"")
 
-        return stderr.strip().decode('utf-8')
+        return stderr.strip().decode("utf-8")
 
     def get_php_upstream(self):
         if not settings.START_PHP:
-            raise Exception('Upstreams are only parsed when START_PHP is True')
+            raise Exception("Upstreams are only parsed when START_PHP is True")
         return self.upstreams.get("php")
 
     def parse_upstreams(self):
         # define basic building blocks
         integer = Word(nums)
         ip_int = integer.copy().setParseAction(validInRange(0, 255))
-        ip_addr = Combine(ip_int + ('.' + ip_int) * 3)
+        ip_addr = Combine(ip_int + ("." + ip_int) * 3)
         ip_port = integer.copy().setParseAction(validInRange(1025, 65535))
         ip_addr_port = ip_addr("ip_addr") + ':' + ip_port("ip_port")
         ident = Word(alphas, alphanums + "_")

File services/PHP.py

 import subprocess
-import os
 from tools import win32_kill
 import settings
 
         for address in self.addresses:
             self.processes.append(
                 subprocess.Popen(
-                    args = [self.executable, "-b", address, '-c', self.ini],
+                    args = [self.executable, "-b", address, "-c", self.ini],
                     cwd = self.path
                 )
             )
 
     def __str__(self):
-        args = [self.executable, '--version', '-c', self.ini]
+        args = [self.executable, "--version", "-c", self.ini]
 
         proc = subprocess.Popen(args=args, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout, stderr = proc.communicate()
         stdout_lines = stdout.splitlines()
 
-        return stdout_lines[0].decode('utf-8')
+        return stdout_lines[0].decode("utf-8")
 
     def stop(self):
         for process in self.processes:
 import os
 
-NGINX_CWD = os.path.join('C:\\', 'opt', 'nginx')
-NGINX_EXECUTABLE = os.path.join(NGINX_CWD, 'nginx.exe')
-NGINX_CONF = os.path.join(NGINX_CWD, 'conf', 'nginx.conf')
-PHP_CWD = os.path.join('C:\\', 'opt', 'php-5.4')
-PHP_EXECUTABLE = os.path.join(PHP_CWD, 'php-cgi.exe')
-PHP_INI = os.path.join(PHP_CWD, 'php.ini')
-MONGODB_CWD = os.path.join('E:\\', 'bin', 'srv', 'mongodb')
-MONGODB_EXECUTABLE = os.path.join(MONGODB_CWD, 'bin', 'mongod.exe')
-MONGODB_CLIENT_EXECUTABLE = os.path.join(MONGODB_CWD, 'bin', 'mongo.exe')
-MONGODB_CONF = os.path.join(MONGODB_CWD, 'mongodb.conf')
+NGINX_CWD = os.path.join("C:\\", "opt", "nginx")
+NGINX_EXECUTABLE = os.path.join(NGINX_CWD, "nginx.exe")
+NGINX_CONF = os.path.join(NGINX_CWD, "conf", "nginx.conf")
+PHP_CWD = os.path.join("C:\\", "opt", "php-5.4")
+PHP_EXECUTABLE = os.path.join(PHP_CWD, "php-cgi.exe")
+PHP_INI = os.path.join(PHP_CWD, "php.ini")
+MONGODB_CWD = os.path.join("E:\\", "bin", "srv", "mongodb")
+MONGODB_EXECUTABLE = os.path.join(MONGODB_CWD, "bin", "mongod.exe")
+MONGODB_CLIENT_EXECUTABLE = os.path.join(MONGODB_CWD, "bin", "mongo.exe")
+MONGODB_CONF = os.path.join(MONGODB_CWD, "mongodb.conf")
 
 START_NGINX = True
 START_PHP = True