added toggle bootstrap command

master
Kevin Froman 2019-12-29 11:21:18 -06:00
parent 87ea8d137b
commit e9f0e60608
4 changed files with 58 additions and 3 deletions

View File

@ -14,9 +14,10 @@ from .. import resettor # cmds to reset the tor data folder/transport keypair
from .. import resetplugins # command to reinstall default plugins from .. import resetplugins # command to reinstall default plugins
from .. import softreset # command to delete onionr blocks from .. import softreset # command to delete onionr blocks
from .. import restartonionr # command to restart Onionr from .. import restartonionr # command to restart Onionr
from .. import runtimetestcmd from .. import runtimetestcmd # cmd to execute the runtime integration tests
from .. import motdcreator from .. import motdcreator # cmd to generate new Onionr MOTDs
from .. import sitecreator from .. import sitecreator # cmd to create multi-page sites
from .. import togglebootstrap # cmd to toggle bootstrap file usage
import onionrexceptions import onionrexceptions
from onionrutils import importnewblocks # func to import new blocks from onionrutils import importnewblocks # func to import new blocks
@ -70,6 +71,8 @@ def get_arguments() -> dict:
('resetplugins', 'reset-plugins'): resetplugins.reset, ('resetplugins', 'reset-plugins'): resetplugins.reset,
('reset-tor-node-transport',): resettor.reset_tor_key_pair, ('reset-tor-node-transport',): resettor.reset_tor_key_pair,
('soft-reset', 'softreset'): softreset.soft_reset, ('soft-reset', 'softreset'): softreset.soft_reset,
('toggle-bootstrap', 'togglebootstrap'):
togglebootstrap.toggle_bootstrap_config,
('runtime-test', 'runtimetest'): runtimetestcmd.do_runtime_test, ('runtime-test', 'runtimetest'): runtimetestcmd.do_runtime_test,
('makemotd', 'make-motd'): motdcreator.motd_creator ('makemotd', 'make-motd'): motdcreator.motd_creator

View File

@ -0,0 +1,32 @@
"""Onionr - Private P2P Communication.
Toggle the bootstrap configuration
"""
import sys
import config
import logger
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
def toggle_bootstrap_config():
"""Toggles the bootstrap configuration."""
print("test")
if config.get('general.use_bootstrap_list') is None:
logger.error('No general.bootstrap_list setting found')
sys.exit(3)
flipped: bool = not config.get('general.use_bootstrap_list')
config.set('general.use_bootstrap_list', flipped, savefile=True)

View File

@ -0,0 +1,20 @@
from unittest.mock import patch
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
import config
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
from onionrcommands import parser
class TestToggleBootstrap(unittest.TestCase):
def test_toggle_bootstrap(self):
testargs = ["onionr.py", "togglebootstrap"]
self.assertTrue(config.get('general.use_bootstrap_list'))
with patch.object(sys, 'argv', testargs):
parser.register()
config.reload()
self.assertFalse(config.get('general.use_bootstrap_list'))
unittest.main()