def create_phantom_site(self): from Config import config from Crypt import CryptBitcoin from Site import Site import os config.parse(silent=True) if not config.arguments: config.parse() self.private_key = CryptBitcoin.newPrivatekey() self.address = CryptBitcoin.privatekeyToAddress(self.private_key) try: os.mkdir("%s/%s" % (config.data_dir, self.address)) open("%s/%s/index.html" % (config.data_dir, self.address), "w").write("Hello %s!" % self.address) except Exception as e: return self.error_msg.error_response("err_create_sitedir") try: self.site = Site(self.address) self.site.content_manager.sign(privatekey=self.private_key, extend={"postmessage_nonce_security": True}) self.site.settings["own"] = True self.site.saveSettings() except Exception as e: print e return self.error_msg.error_response("err_create_site") return {"jsonrpc": "2.0", "id": "1", "result": ["true", str(self.address), str(self.private_key)]}
from gevent import monkey if "patch_subprocess" in dir(monkey): # New gevent monkey.patch_all(thread=False, subprocess=False) else: # Old gevent import ssl # Fix PROTOCOL_SSLv3 not defined if "PROTOCOL_SSLv3" not in dir(ssl): ssl.PROTOCOL_SSLv3 = ssl.PROTOCOL_SSLv23 monkey.patch_all(thread=False) # Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+ update_after_shutdown = False # If set True then update and restart zeronet after main loop ended # Load config from Config import config config.parse(silent=True) # Plugins need to access the configuration if not config.arguments: # Config parse failed, show the help screen and exit config.parse() # Create necessary files and dirs if not os.path.isdir(config.log_dir): os.mkdir(config.log_dir) try: os.chmod(config.log_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) except Exception, err: print "Can't change permission of %s: %s" % (config.log_dir, err) if not os.path.isdir(config.data_dir): os.mkdir(config.data_dir) try: os.chmod(config.data_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
import mock # Config if sys.platform == "win32": PHANTOMJS_PATH = "tools/phantomjs/bin/phantomjs.exe" else: PHANTOMJS_PATH = "phantomjs" SITE_URL = "http://127.0.0.1:43110" # Imports relative to src dir sys.path.append( os.path.abspath(os.path.dirname(__file__) + "/..") ) from Config import config config.argv = ["none"] # Dont pass any argv to config parser config.parse() config.data_dir = "src/Test/testdata" # Use test data for unittests logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) from Site import Site from User import UserManager from File import FileServer from Connection import ConnectionServer from Crypt import CryptConnection import gevent from gevent import monkey monkey.patch_all(thread=False) @pytest.fixture(scope="session") def resetSettings(request):
if "patch_subprocess" in dir(monkey): # New gevent monkey.patch_all(thread=False, subprocess=False) else: # Old gevent import ssl # Fix PROTOCOL_SSLv3 not defined if "PROTOCOL_SSLv3" not in dir(ssl): ssl.PROTOCOL_SSLv3 = ssl.PROTOCOL_SSLv23 monkey.patch_all(thread=False) # Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+ update_after_shutdown = False # If set True then update and restart zeronet after main loop ended restart_after_shutdown = False # If set True then restart zeronet after main loop ended # Load config from Config import config config.parse(silent=True) # Plugins need to access the configuration if not config.arguments: # Config parse failed, show the help screen and exit config.parse() # Create necessary files and dirs if not os.path.isdir(config.log_dir): os.mkdir(config.log_dir) try: os.chmod(config.log_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) except Exception as err: print "Can't change permission of %s: %s" % (config.log_dir, err) if not os.path.isdir(config.data_dir): os.mkdir(config.data_dir) try: os.chmod(config.data_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
else: data = open(updatesite_path + "/" + inner_path, "rb").read() try: open(dest_path, 'wb').write(data) except Exception, err: print dest_path, err print "Done." return True if __name__ == "__main__": import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src from gevent import monkey monkey.patch_all() from Config import config config.parse(silent=True) from src.util import SslPatch try: update() except Exception, err: print "Update error: %s" % err raw_input("Press enter to exit")
if dest_dir != dest_path.strip("/"): if zipdata: data = zipdata.read(inner_path) else: data = open(updatesite_path + "/" + inner_path, "rb").read() try: open(dest_path, 'wb').write(data) except Exception, err: print dest_path, err print "Done." return True if __name__ == "__main__": # Fix broken gevent SSL import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src from Config import config config.parse() from src.util import SslPatch try: update() except Exception, err: print "Update error: %s" % err raw_input("Press enter to exit")
data = zipdata.read(inner_path) else: data = open(updatesite_path + "/" + inner_path, "rb").read() try: open(dest_path, 'wb').write(data) except Exception, err: print dest_path, err print "Done." return True if __name__ == "__main__": import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src from gevent import monkey monkey.patch_all() from Config import config config.parse(silent=True) from src.util import SslPatch try: update() except Exception, err: print "Update error: %s" % err raw_input("Press enter to exit")
# Config if sys.platform == "win32": CHROMEDRIVER_PATH = "tools/chrome/chromedriver.exe" else: CHROMEDRIVER_PATH = "chromedriver" SITE_URL = "http://127.0.0.1:43110" TEST_DATA_PATH = 'src/Test/testdata' sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/../lib")) # External modules directory sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/..")) # Imports relative to src dir from Config import config config.argv = ["none"] # Dont pass any argv to config parser config.parse(silent=True, parse_config=False) # Plugins need to access the configuration config.action = "test" # Load plugins from Plugin import PluginManager config.data_dir = TEST_DATA_PATH # Use test data for unittests config.debug = True os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir all_loaded = PluginManager.plugin_manager.loadPlugins() assert all_loaded, "Not all plugin loaded successfully" config.loadPlugins()