Merge pull request #1124 from imachug/zeronetpy3
Move server info formatting to Config.py; use it via getConfig console command
This commit is contained in:
commit
20a063105c
2 changed files with 35 additions and 0 deletions
|
@ -165,6 +165,8 @@ class Config(object):
|
|||
action.add_argument('message', help='Message to sign')
|
||||
action.add_argument('privatekey', help='Private key')
|
||||
|
||||
action = self.subparsers.add_parser("getConfig", help='Return json-encoded info')
|
||||
|
||||
# Config parameters
|
||||
self.parser.add_argument('--verbose', help='More detailed logging', action='store_true')
|
||||
self.parser.add_argument('--debug', help='Debug mode', action='store_true')
|
||||
|
@ -408,4 +410,33 @@ class Config(object):
|
|||
|
||||
open(self.config_file, "w").write("\n".join(lines))
|
||||
|
||||
def getServerInfo(self):
|
||||
from Plugin import PluginManager
|
||||
|
||||
info = {
|
||||
"platform": sys.platform,
|
||||
"fileserver_ip": self.fileserver_ip,
|
||||
"fileserver_port": self.fileserver_port,
|
||||
"ui_ip": self.ui_ip,
|
||||
"ui_port": self.ui_port,
|
||||
"version": self.version,
|
||||
"rev": self.rev,
|
||||
"language": self.language,
|
||||
"debug": self.debug,
|
||||
"plugins": PluginManager.plugin_manager.plugin_names,
|
||||
|
||||
"log_dir": os.path.abspath(self.log_dir),
|
||||
"data_dir": os.path.abspath(self.data_dir),
|
||||
"src_dir": os.path.dirname(os.path.abspath(__file__))
|
||||
}
|
||||
|
||||
try:
|
||||
info["ip_external"] = sys.modules["main"].file_server.port_opened
|
||||
info["tor_enabled"] = sys.modules["main"].file_server.tor_manager.enabled
|
||||
info["tor_status"] = sys.modules["main"].file_server.tor_manager.status
|
||||
except:
|
||||
pass
|
||||
|
||||
return info
|
||||
|
||||
config = Config(sys.argv)
|
||||
|
|
|
@ -481,6 +481,10 @@ class Actions(object):
|
|||
except Exception, err:
|
||||
print "Unknown response (%s): %s" % (err, res)
|
||||
|
||||
def getConfig(self):
|
||||
import json
|
||||
print json.dumps(config.getServerInfo(), indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
actions = Actions()
|
||||
# Starts here when running zeronet.py
|
||||
|
|
Loading…
Reference in a new issue