Commit 1d8a9ff6 authored by Matt Traudt's avatar Matt Traudt
Browse files

Move fail_hard to globals; use is_initted in init command

parent d9ae7d82
......@@ -5,7 +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
from sbws.globals import (fail_hard, is_initted)
import sbws.util.stem as stem_utils
from stem.control import EventType
from argparse import ArgumentDefaultsHelpFormatter
......@@ -28,14 +28,6 @@ DOWNLOAD_TIMES = {'toofast': 1, 'min': 5, 'target': 6, 'max': 10}
DESIRED_RESULTS = 5
def fail_hard(*s):
''' Optionally log something to stdout ... and then exit as fast as
possible '''
if s:
log.error(*s)
exit(1)
def make_socket(socks_host, socks_port):
''' Make a socket that uses the provided socks5 proxy. Note at this point
the socket hasn't connect()ed anywhere '''
......
from sbws.globals import G_INIT_FILE_MAP
from sbws.globals import (G_INIT_FILE_MAP, is_initted, fail_hard)
from ..lib.pastlylogger import PastlyLogger
from argparse import ArgumentDefaultsHelpFormatter
import os
......@@ -7,14 +7,6 @@ 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)
......@@ -23,11 +15,11 @@ def main(args):
global log
log = PastlyLogger(debug='/dev/stdout', overwrite=['debug'],
log_threads=True)
if is_initted(os.getcwd()):
fail_hard('Directory already seems to be initted')
dotdir = os.path.join(os.getcwd(), '.sbws')
if os.path.exists(dotdir):
fail_hard('Directory already seems to be initted')
os.makedirs(dotdir)
os.makedirs(dotdir, exist_ok=True)
for src, dst, ftype in G_INIT_FILE_MAP:
log.info(dst, '({})'.format(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 sbws.globals import (fail_hard, is_initted)
from argparse import ArgumentDefaultsHelpFormatter
from threading import Thread
import socket
......@@ -25,14 +25,6 @@ def gen_parser(sub):
'valid passwords scanners may use to authenticate.')
def fail_hard(*s):
''' Optionally log something to stdout ... and then exit as fast as
possible '''
if s:
log.error(*s)
exit(1)
def read_line(s):
''' read until b'\n' is seen on the socket <s>. Return everything up until
the newline as a str. If nothing can be read, return None. Note how that is
......
......@@ -17,3 +17,12 @@ def is_initted(d):
if not os.path.exists(fname):
return False
return True
def fail_hard(*s):
''' Optionally log something to stdout ... and then exit as fast as
possible '''
if s:
# log.error(*s)
print(*s)
exit(1)
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