tahoe: Styling changes

- Run yapf and isort

- Minor styling changes

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-02-14 16:35:48 -08:00 committed by James Valleroy
parent 96e7fd3e40
commit c7f46c358d
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -20,27 +20,23 @@ Configuration helper for Tahoe-LAFS.
""" """
import argparse import argparse
import augeas
import grp import grp
import json import json
import os
import pwd import pwd
import shutil import shutil
import subprocess import subprocess
import os import augeas
import ruamel.yaml import ruamel.yaml
from plinth import action_utils from plinth import action_utils
from plinth.modules.tahoe import ( from plinth.modules.tahoe import (introducer_furl_file, introducer_name,
introducer_name, introducers_file, storage_node_name,
introducers_file, tahoe_home)
storage_node_name,
tahoe_home,
introducer_furl_file)
from plinth.modules.tahoe.errors import TahoeConfigurationError from plinth.modules.tahoe.errors import TahoeConfigurationError
from plinth.utils import YAMLFile from plinth.utils import YAMLFile
domain_name_file = os.path.join(tahoe_home, 'domain_name') domain_name_file = os.path.join(tahoe_home, 'domain_name')
DEFAULT_FILE = '/etc/default/tahoe-lafs' DEFAULT_FILE = '/etc/default/tahoe-lafs'
@ -61,30 +57,31 @@ def parse_arguments():
help='Create and start the introducer node') help='Create and start the introducer node')
subparsers.add_parser('create-storage-node', subparsers.add_parser('create-storage-node',
help='Create and start the storage node') help='Create and start the storage node')
subparsers.add_parser('autostart', subparsers.add_parser(
help="Automatically start all introducers and " 'autostart', help='Automatically start all introducers and '
"storage nodes on system startup") 'storage nodes on system startup')
intro_parser_add = subparsers.add_parser( intro_parser_add = subparsers.add_parser(
'add-introducer', help="Add an introducer to the storage node's list " 'add-introducer', help="Add an introducer to the storage node's list "
"of introducers.") 'of introducers.')
intro_parser_add.add_argument( intro_parser_add.add_argument(
'--introducer', help="Add an introducer to the storage node's list " '--introducer', help="Add an introducer to the storage node's list "
"of introducers Param introducer must be a tuple " 'of introducers Param introducer must be a tuple '
"of (pet_name, furl)") 'of (pet_name, furl)')
intro_parser_remove = subparsers.add_parser( intro_parser_remove = subparsers.add_parser(
'remove-introducer', help="Rename the introducer entry in the " 'remove-introducer', help='Rename the introducer entry in the '
"introducers.yaml file specified by the " 'introducers.yaml file specified by the '
"param") 'param')
intro_parser_remove.add_argument( intro_parser_remove.add_argument(
'--pet-name', help='The domain name that will be used by ' '--pet-name', help='The domain name that will be used by '
'Tahoe-LAFS') 'Tahoe-LAFS')
subparsers.add_parser('get-introducers', subparsers.add_parser(
help="Return a dictionary of all introducers and " 'get-introducers', help='Return a dictionary of all introducers and '
"their furls added to the storage node running " 'their furls added to the storage node running '
"on this FreedomBox.") 'on this FreedomBox.')
subparsers.add_parser('get-local-introducer', subparsers.add_parser(
help="Return the name and furl of the introducer " 'get-local-introducer',
"created on this FreedomBox") help='Return the name and furl of the introducer '
'created on this FreedomBox')
return parser.parse_args() return parser.parse_args()
@ -101,13 +98,11 @@ def subcommand_setup(arguments):
try: try:
pwd.getpwnam('tahoe-lafs') pwd.getpwnam('tahoe-lafs')
except KeyError: except KeyError:
subprocess.run( subprocess.run([
[ 'adduser', '--system', '--ingroup', 'tahoe-lafs', '--home',
'adduser', '--system', '--ingroup', 'tahoe-lafs', '/var/lib/tahoe-lafs', '--gecos',
'--home', '/var/lib/tahoe-lafs', 'Tahoe-LAFS distributed file system', 'tahoe-lafs'
'--gecos', 'Tahoe-LAFS distributed file system', 'tahoe-lafs' ], check=True)
],
check=True)
if not os.path.exists(tahoe_home): if not os.path.exists(tahoe_home):
os.makedirs(tahoe_home, mode=0o755) os.makedirs(tahoe_home, mode=0o755)
@ -165,21 +160,20 @@ def subcommand_create_storage_node(_):
if not os.path.exists(os.path.join(tahoe_home, storage_node_name)): if not os.path.exists(os.path.join(tahoe_home, storage_node_name)):
subprocess.check_call([ subprocess.check_call([
'tahoe', 'create-node', '--nickname=\"storage_node\"', 'tahoe', 'create-node', '--nickname=\"storage_node\"',
'--webport=1234', '--webport=1234', '--hostname={}'.format(
'--hostname={}'.format(get_configured_domain_name()), get_configured_domain_name()), storage_node_name
storage_node_name
]) ])
with open( with open(
os.path.join(tahoe_home, introducer_name, 'private', os.path.join(tahoe_home, introducer_name, 'private',
introducer_name + '.furl'), 'r') as furl_file: introducer_name + '.furl'), 'r') as furl_file:
furl = furl_file.read().rstrip() furl = furl_file.read().rstrip()
conf_dict = {'introducers': {introducer_name: {'furl': furl}}} conf_dict = {'introducers': {introducer_name: {'furl': furl}}}
conf_yaml = ruamel.yaml.dump( conf_yaml = ruamel.yaml.dump(conf_dict,
conf_dict, Dumper=ruamel.yaml.RoundTripDumper) Dumper=ruamel.yaml.RoundTripDumper)
with open( with open(
os.path.join(tahoe_home, storage_node_name, 'private', os.path.join(tahoe_home, storage_node_name, 'private',
'introducers.yaml'), 'w') as introducers_file: 'introducers.yaml'), 'w') as file_handle:
introducers_file.write(conf_yaml) file_handle.write(conf_yaml)
subprocess.call(['tahoe', 'start', storage_node_name]) subprocess.call(['tahoe', 'start', storage_node_name])
@ -190,8 +184,9 @@ def subcommand_add_introducer(arguments):
Param introducer must be a tuple of (pet_name, furl). Param introducer must be a tuple of (pet_name, furl).
""" """
with YAMLFile(introducers_file) as conf: with YAMLFile(introducers_file) as conf:
pet_name, furl = arguments.introducer.split(",") pet_name, furl = arguments.introducer.split(',')
conf['introducers'][pet_name] = {'furl': furl} conf['introducers'][pet_name] = {'furl': furl}
restart_storage_node() restart_storage_node()
@ -201,6 +196,7 @@ def subcommand_remove_introducer(arguments):
""" """
with YAMLFile(introducers_file) as conf: with YAMLFile(introducers_file) as conf:
del conf['introducers'][arguments.pet_name] del conf['introducers'][arguments.pet_name]
restart_storage_node() restart_storage_node()