Commit d9ae7d82 authored by Matt Traudt's avatar Matt Traudt
Browse files

Add init command

parent 5ab6c6fc
......@@ -18,6 +18,7 @@ Clone the repo
virtualenv -p python3 venv
source venv/bin/activate
pip install .
sbws init
sbws client -h
sbws server -h
......
import sbws.commands.client
import sbws.commands.init
import sbws.commands.server
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
......@@ -10,6 +11,7 @@ def create_parser():
p = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
sub = p.add_subparsers(dest='command')
sbws.commands.client.gen_parser(sub)
sbws.commands.init.gen_parser(sub)
sbws.commands.server.gen_parser(sub)
return p
......@@ -22,6 +24,8 @@ def main():
known_commands = {
'client': {'f': sbws.commands.client.main,
'a': def_args, 'kw': def_kwargs},
'init': {'f': sbws.commands.init.main,
'a': def_args, 'kw': def_kwargs},
'server': {'f': sbws.commands.server.main,
'a': def_args, 'kw': def_kwargs},
}
......
......@@ -5,6 +5,7 @@ from ..lib.resultdump import Result
from ..lib.relaylist import RelayList
from ..util.simpleauth import is_good_clientside_password_file
from ..util.simpleauth import authenticate_to_server
from sbws.globals import is_initted
import sbws.util.stem as stem_utils
from stem.control import EventType
from argparse import ArgumentDefaultsHelpFormatter
......@@ -15,6 +16,7 @@ import random
import socks
import socket
import time
import os
log = None
......@@ -273,6 +275,8 @@ def main(args):
global log
log = PastlyLogger(debug='/dev/stdout', overwrite=['debug'],
log_threads=True)
if not is_initted(os.getcwd()):
fail_hard('Directory isn\'t initted')
if args.threads < 1:
fail_hard('--threads must be larger than 1')
......
from sbws.globals import G_INIT_FILE_MAP
from ..lib.pastlylogger import PastlyLogger
from argparse import ArgumentDefaultsHelpFormatter
import os
import shutil
log = None
def fail_hard(*s):
''' Optionally log something to stdout ... and then exit as fast as
possible '''
if s:
log.error(*s)
exit(1)
def gen_parser(sub):
p = sub.add_parser('init', formatter_class=ArgumentDefaultsHelpFormatter)
def main(args):
global log
log = PastlyLogger(debug='/dev/stdout', overwrite=['debug'],
log_threads=True)
dotdir = os.path.join(os.getcwd(), '.sbws')
if os.path.exists(dotdir):
fail_hard('Directory already seems to be initted')
os.makedirs(dotdir)
for src, dst, ftype in G_INIT_FILE_MAP:
log.info(dst, '({})'.format(ftype))
if ftype == 'file':
shutil.copy(src, dst)
else:
fail_hard('Cannot init ftype', ftype)
from ..lib.pastlylogger import PastlyLogger
from ..util.simpleauth import authenticate_client
from ..util.simpleauth import is_good_serverside_password_file
from sbws.globals import is_initted
from argparse import ArgumentDefaultsHelpFormatter
from threading import Thread
import socket
import time
import os
log = None
......@@ -108,6 +110,9 @@ def main(args):
global log
log = PastlyLogger(debug='/dev/stdout', overwrite=['debug'],
log_threads=True)
if not is_initted(os.getcwd()):
fail_hard('Directory isn\'t initted')
valid, error_reason = is_good_serverside_password_file(args.password_file)
if not valid:
fail_hard(error_reason)
......
import os
G_PKG_DIR = os.path.abspath(os.path.dirname(__file__))
G_INIT_FILE_MAP = [
# (source, destination, type)
(os.path.join(G_PKG_DIR, 'passwords.txt.example'),
'passwords.txt', 'file'),
]
def is_initted(d):
dotdir = os.path.join(d, '.sbws')
if not os.path.isdir(dotdir):
return False
for _, fname, _ in G_INIT_FILE_MAP:
if not os.path.exists(fname):
return False
return True
......@@ -19,6 +19,10 @@ def get_package_data():
# for f in fs:
# other_files.append(os.path.join(r, f))
# return other_files
return ['passwords.txt.example']
def get_data_files():
return []
......@@ -49,9 +53,10 @@ setup(
'Development Status :: 3 - Alpha',
],
packages=find_packages(),
# package_data={
# 'foo': get_package_data(),
# },
package_data={
'sbws': get_package_data(),
},
data_files=get_data_files(),
keywords='',
python_requires='>=3.5',
# test_suite='test',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment