setup.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import subprocess
  2. import sys
  3. import setup_util
  4. import os
  5. from zipfile import ZipFile
  6. def start(args, logfile, errfile):
  7. setup_util.replace_text("play-scala-mongodb/conf/application.conf", "jdbc:mysql:\/\/.*:3306", "jdbc:mysql://" + args.database_host + ":3306")
  8. subprocess.check_call("play clean dist", shell=True, cwd="play-scala-mongodb", stderr=errfile, stdout=logfile)
  9. if os.name == 'nt':
  10. ZipFile("./play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT.zip").extractall("./play-scala-mongodb/target/universal")
  11. with open("./play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT/bin/play-scala-mongodb.bat", "w+") as f:
  12. f.write("java %1 -cp \"./lib/*;\" play.core.server.NettyServer .")
  13. subprocess.Popen("play-scala-mongodb.bat", shell=True, cwd="play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT/bin", stderr=errfile, stdout=logfile)
  14. else:
  15. subprocess.check_call("unzip play-scala-mongodb-1.0-SNAPSHOT.zip", shell=True, cwd="play-scala-mongodb/target/universal", stderr=errfile, stdout=logfile)
  16. subprocess.check_call("chmod +x play-scala-mongodb", shell=True, cwd="play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT/bin", stderr=errfile, stdout=logfile)
  17. subprocess.Popen("./play-scala-mongodb", shell=True, cwd="play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT/bin", stderr=errfile, stdout=logfile)
  18. return 0
  19. def stop(logfile, errfile):
  20. if os.name == 'nt':
  21. with open("./play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT/RUNNING_PID") as f:
  22. pid = int(f.read())
  23. os.kill(pid, 15)
  24. else:
  25. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  26. out, err = p.communicate()
  27. for line in out.splitlines():
  28. if 'NettyServer' in line:
  29. pid = int(line.split(None, 2)[1])
  30. os.kill(pid, 15)
  31. try:
  32. os.remove("play-scala-mongodb/target/universal/play-scala-mongodb-1.0-SNAPSHOT/RUNNING_PID")
  33. except OSError:
  34. return 1
  35. # Takes up so much disk space
  36. if os.name == 'nt':
  37. subprocess.check_call("del /f /s /q target", shell=True, cwd="play-scala-mongodb", stderr=errfile, stdout=logfile)
  38. else:
  39. subprocess.check_call("rm -rf target", shell=True, cwd="play-scala-mongodb", stderr=errfile, stdout=logfile)
  40. return 0