zeronet.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python2.7
  2. # Included modules
  3. import os
  4. import sys
  5. def main():
  6. print "- Starting ZeroNet..."
  7. main = None
  8. try:
  9. sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src/lib")) # External liblary directory
  10. sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src
  11. import main
  12. main.start()
  13. if main.update_after_shutdown: # Updater
  14. import gc
  15. import update
  16. # Try cleanup openssl
  17. try:
  18. if "lib.opensslVerify" in sys.modules:
  19. sys.modules["lib.opensslVerify"].opensslVerify.closeLibrary()
  20. except Exception, err:
  21. print "Error closing opensslVerify lib", err
  22. try:
  23. if "lib.pyelliptic" in sys.modules:
  24. sys.modules["lib.pyelliptic"].openssl.closeLibrary()
  25. except Exception, err:
  26. print "Error closing pyelliptic lib", err
  27. # Update
  28. update.update()
  29. # Close log files
  30. logger = sys.modules["main"].logging.getLogger()
  31. for handler in logger.handlers[:]:
  32. handler.flush()
  33. handler.close()
  34. logger.removeHandler(handler)
  35. except (Exception, ): # Prevent closing
  36. import traceback
  37. traceback.print_exc()
  38. traceback.print_exc(file=open("log/error.log", "a"))
  39. if main and main.update_after_shutdown: # Updater
  40. # Restart
  41. gc.collect() # Garbage collect
  42. print "Restarting..."
  43. import time
  44. time.sleep(1) # Wait files to close
  45. args = sys.argv[:]
  46. args.insert(0, sys.executable)
  47. if sys.platform == 'win32':
  48. args = ['"%s"' % arg for arg in args]
  49. os.execv(sys.executable, args)
  50. print "Bye."
  51. if __name__ == '__main__':
  52. main()