mirror of
https://github.com/onionshare/onionshare.git
synced 2025-03-08 14:15:58 -05:00
Refactor the CLI main function to explicitly use 'share' or 'receive' mode
This commit is contained in:
parent
cc9f646f8b
commit
a86681e903
@ -65,13 +65,18 @@ def main(cwd=None):
|
|||||||
receive = bool(args.receive)
|
receive = bool(args.receive)
|
||||||
config = args.config
|
config = args.config
|
||||||
|
|
||||||
|
if receive:
|
||||||
|
mode = 'receive'
|
||||||
|
else:
|
||||||
|
mode = 'share'
|
||||||
|
|
||||||
# Make sure filenames given if not using receiver mode
|
# Make sure filenames given if not using receiver mode
|
||||||
if not receive and len(filenames) == 0:
|
if mode == 'share' and len(filenames) == 0:
|
||||||
print(strings._('no_filenames'))
|
print(strings._('no_filenames'))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Validate filenames
|
# Validate filenames
|
||||||
if not receive:
|
if mode == 'share':
|
||||||
valid = True
|
valid = True
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not os.path.isfile(filename) and not os.path.isdir(filename):
|
if not os.path.isfile(filename) and not os.path.isdir(filename):
|
||||||
@ -90,7 +95,7 @@ def main(cwd=None):
|
|||||||
common.debug = debug
|
common.debug = debug
|
||||||
|
|
||||||
# Create the Web object
|
# Create the Web object
|
||||||
web = Web(common, False, receive)
|
web = Web(common, False, mode)
|
||||||
|
|
||||||
# Start the Onion object
|
# Start the Onion object
|
||||||
onion = Onion(common)
|
onion = Onion(common)
|
||||||
@ -116,21 +121,22 @@ def main(cwd=None):
|
|||||||
print(e.args[0])
|
print(e.args[0])
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Prepare files to share
|
if mode == 'share':
|
||||||
print(strings._("preparing_files"))
|
# Prepare files to share
|
||||||
try:
|
print(strings._("preparing_files"))
|
||||||
web.share_mode.set_file_info(filenames)
|
try:
|
||||||
if web.is_zipped:
|
web.share_mode.set_file_info(filenames)
|
||||||
app.cleanup_filenames.append(web.download_filename)
|
if web.is_zipped:
|
||||||
except OSError as e:
|
app.cleanup_filenames.append(web.download_filename)
|
||||||
print(e.strerror)
|
except OSError as e:
|
||||||
sys.exit(1)
|
print(e.strerror)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Warn about sending large files over Tor
|
# Warn about sending large files over Tor
|
||||||
if web.download_filesize >= 157286400: # 150mb
|
if web.download_filesize >= 157286400: # 150mb
|
||||||
print('')
|
print('')
|
||||||
print(strings._("large_filesize"))
|
print(strings._("large_filesize"))
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
# Start OnionShare http service in new thread
|
# Start OnionShare http service in new thread
|
||||||
t = threading.Thread(target=web.start, args=(app.port, stay_open, common.settings.get('public_mode'), common.settings.get('slug')))
|
t = threading.Thread(target=web.start, args=(app.port, stay_open, common.settings.get('public_mode'), common.settings.get('slug')))
|
||||||
@ -158,7 +164,7 @@ def main(cwd=None):
|
|||||||
url = 'http://{0:s}/{1:s}'.format(app.onion_host, web.slug)
|
url = 'http://{0:s}/{1:s}'.format(app.onion_host, web.slug)
|
||||||
|
|
||||||
print('')
|
print('')
|
||||||
if receive:
|
if mode == 'receive':
|
||||||
print(strings._('receive_mode_downloads_dir').format(common.settings.get('downloads_dir')))
|
print(strings._('receive_mode_downloads_dir').format(common.settings.get('downloads_dir')))
|
||||||
print('')
|
print('')
|
||||||
print(strings._('receive_mode_warning'))
|
print(strings._('receive_mode_warning'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user