Add support for programmatic command creation
parent
f72cb5426c
commit
b04ea55e48
|
@ -34,6 +34,9 @@ ONIONR_VERSION = '0.0.0' # for debugging and stuff
|
||||||
API_VERSION = '1' # increments of 1; only change when something fundemental about how the API works changes. This way other nodes knows how to communicate without learning too much information about you.
|
API_VERSION = '1' # increments of 1; only change when something fundemental about how the API works changes. This way other nodes knows how to communicate without learning too much information about you.
|
||||||
|
|
||||||
class Onionr:
|
class Onionr:
|
||||||
|
cmds = {}
|
||||||
|
cmdhelp = {}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
'''
|
'''
|
||||||
Main Onionr class. This is for the CLI program, and does not handle much of the logic.
|
Main Onionr class. This is for the CLI program, and does not handle much of the logic.
|
||||||
|
@ -109,27 +112,7 @@ class Onionr:
|
||||||
break
|
break
|
||||||
config.set('CLIENT', {'participate': 'true', 'CLIENT HMAC': base64.b64encode(os.urandom(32)).decode('utf-8'), 'PORT': randomPort, 'API VERSION': API_VERSION}, True)
|
config.set('CLIENT', {'participate': 'true', 'CLIENT HMAC': base64.b64encode(os.urandom(32)).decode('utf-8'), 'PORT': randomPort, 'API VERSION': API_VERSION}, True)
|
||||||
|
|
||||||
command = ''
|
self.cmds = {
|
||||||
try:
|
|
||||||
command = sys.argv[1].lower()
|
|
||||||
except IndexError:
|
|
||||||
command = ''
|
|
||||||
finally:
|
|
||||||
self.execute(command)
|
|
||||||
|
|
||||||
if not self._developmentMode:
|
|
||||||
encryptionPassword = self.onionrUtils.getPassword('Enter password to encrypt directory: ')
|
|
||||||
self.onionrCore.dataDirEncrypt(encryptionPassword)
|
|
||||||
shutil.rmtree('data/')
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
'''
|
|
||||||
THIS SECTION HANDLES THE COMMANDS
|
|
||||||
'''
|
|
||||||
|
|
||||||
def getCommands(self):
|
|
||||||
return {
|
|
||||||
'': self.showHelpSuggestion,
|
'': self.showHelpSuggestion,
|
||||||
'help': self.showHelp,
|
'help': self.showHelp,
|
||||||
'version': self.version,
|
'version': self.version,
|
||||||
|
@ -170,8 +153,7 @@ class Onionr:
|
||||||
'connect': self.addAddress
|
'connect': self.addAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
def getHelp(self):
|
self.cmdhelp = {
|
||||||
return {
|
|
||||||
'help': 'Displays this Onionr help menu',
|
'help': 'Displays this Onionr help menu',
|
||||||
'version': 'Displays the Onionr version',
|
'version': 'Displays the Onionr version',
|
||||||
'config': 'Configures something and adds it to the file',
|
'config': 'Configures something and adds it to the file',
|
||||||
|
@ -188,6 +170,37 @@ class Onionr:
|
||||||
'gui': 'Opens a graphical interface for Onionr'
|
'gui': 'Opens a graphical interface for Onionr'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command = ''
|
||||||
|
try:
|
||||||
|
command = sys.argv[1].lower()
|
||||||
|
except IndexError:
|
||||||
|
command = ''
|
||||||
|
finally:
|
||||||
|
self.execute(command)
|
||||||
|
|
||||||
|
if not self._developmentMode:
|
||||||
|
encryptionPassword = self.onionrUtils.getPassword('Enter password to encrypt directory: ')
|
||||||
|
self.onionrCore.dataDirEncrypt(encryptionPassword)
|
||||||
|
shutil.rmtree('data/')
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
'''
|
||||||
|
THIS SECTION HANDLES THE COMMANDS
|
||||||
|
'''
|
||||||
|
|
||||||
|
def getCommands(self):
|
||||||
|
return self.cmds
|
||||||
|
|
||||||
|
def getHelp(self):
|
||||||
|
return self.cmdhelp
|
||||||
|
|
||||||
|
def addCommand(self, command, function):
|
||||||
|
cmds[str(command).lower()] = function
|
||||||
|
|
||||||
|
def addHelp(self, command, description):
|
||||||
|
cmdhelp[str(command).lower()] = str(description)
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
'''
|
'''
|
||||||
Displays something from the configuration file, or sets it
|
Displays something from the configuration file, or sets it
|
||||||
|
|
Loading…
Reference in New Issue