|
|
@ -8,9 +8,10 @@ import sys |
|
|
|
from configparser import ConfigParser |
|
|
|
from configparser import ConfigParser |
|
|
|
from getpass import getpass |
|
|
|
from getpass import getpass |
|
|
|
|
|
|
|
|
|
|
|
from api import StandardNotesAPI |
|
|
|
from api import StandardNotesAPI, SNAPIException |
|
|
|
from sn_fuse import StandardNotesFUSE |
|
|
|
from sn_fuse import StandardNotesFUSE |
|
|
|
from fuse import FUSE |
|
|
|
from fuse import FUSE |
|
|
|
|
|
|
|
from requests.exceptions import ConnectionError, MissingSchema |
|
|
|
|
|
|
|
|
|
|
|
OFFICIAL_SERVER_URL = 'https://sync.standardnotes.org' |
|
|
|
OFFICIAL_SERVER_URL = 'https://sync.standardnotes.org' |
|
|
|
DEFAULT_SYNC_SEC = 30 |
|
|
|
DEFAULT_SYNC_SEC = 30 |
|
|
@ -54,6 +55,7 @@ def main(): |
|
|
|
args = parse_options() |
|
|
|
args = parse_options() |
|
|
|
config = ConfigParser() |
|
|
|
config = ConfigParser() |
|
|
|
keys = {} |
|
|
|
keys = {} |
|
|
|
|
|
|
|
login_success = False |
|
|
|
|
|
|
|
|
|
|
|
# configure logging |
|
|
|
# configure logging |
|
|
|
if args.verbosity == 1: |
|
|
|
if args.verbosity == 1: |
|
|
@ -61,7 +63,7 @@ def main(): |
|
|
|
elif args.verbosity == 2: |
|
|
|
elif args.verbosity == 2: |
|
|
|
log_level = logging.DEBUG |
|
|
|
log_level = logging.DEBUG |
|
|
|
else: |
|
|
|
else: |
|
|
|
log_level = logging.CRITICAL |
|
|
|
log_level = logging.ERROR |
|
|
|
logging.basicConfig(level=log_level, |
|
|
|
logging.basicConfig(level=log_level, |
|
|
|
format='%(levelname)-8s: %(message)s') |
|
|
|
format='%(levelname)-8s: %(message)s') |
|
|
|
if args.verbosity: args.foreground = True |
|
|
|
if args.verbosity: args.foreground = True |
|
|
@ -143,18 +145,23 @@ def main(): |
|
|
|
log_msg = 'Successfully logged into account "%s".' |
|
|
|
log_msg = 'Successfully logged into account "%s".' |
|
|
|
logging.info(log_msg % username) |
|
|
|
logging.info(log_msg % username) |
|
|
|
login_success = True |
|
|
|
login_success = True |
|
|
|
except: |
|
|
|
except SNAPIException as e: |
|
|
|
log_msg = 'Failed to log into account "%s".' |
|
|
|
print(e) |
|
|
|
print(log_msg % username) |
|
|
|
except ConnectionError: |
|
|
|
login_success = False |
|
|
|
log_msg = 'Unable to connect to the sync server at "%s".' |
|
|
|
|
|
|
|
print(log_msg % sync_url) |
|
|
|
|
|
|
|
except MissingSchema: |
|
|
|
|
|
|
|
log_msg = 'Invalid sync server url "%s".' |
|
|
|
|
|
|
|
print(log_msg % sync_url) |
|
|
|
|
|
|
|
|
|
|
|
# write settings back if good, clear if not |
|
|
|
# write settings back if good, clear if not |
|
|
|
if not args.no_config_file: |
|
|
|
if not args.no_config_file: |
|
|
|
config.read_dict(dict(user=dict(sync_url=sync_url, username=username), |
|
|
|
|
|
|
|
keys=keys)) |
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
with config_file.open(mode='w+') as f: |
|
|
|
with config_file.open(mode='w+') as f: |
|
|
|
if login_success: |
|
|
|
if login_success: |
|
|
|
|
|
|
|
config.read_dict(dict(user=dict(sync_url=sync_url, |
|
|
|
|
|
|
|
username=username), |
|
|
|
|
|
|
|
keys=keys)) |
|
|
|
config.write(f) |
|
|
|
config.write(f) |
|
|
|
log_msg = 'Config written to file "%s".' |
|
|
|
log_msg = 'Config written to file "%s".' |
|
|
|
logging.info(log_msg % str(config_file)) |
|
|
|
logging.info(log_msg % str(config_file)) |
|
|
@ -168,10 +175,13 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
if login_success: |
|
|
|
if login_success: |
|
|
|
logging.info('Starting FUSE filesystem.') |
|
|
|
logging.info('Starting FUSE filesystem.') |
|
|
|
|
|
|
|
try: |
|
|
|
fuse = FUSE(StandardNotesFUSE(sn_api, sync_sec), |
|
|
|
fuse = FUSE(StandardNotesFUSE(sn_api, sync_sec), |
|
|
|
args.mountpoint, |
|
|
|
args.mountpoint, |
|
|
|
foreground=args.foreground, |
|
|
|
foreground=args.foreground, |
|
|
|
nothreads=True) # benefits don't outweigh the costs |
|
|
|
nothreads=True) # FUSE can't make threads, but we can |
|
|
|
|
|
|
|
except RuntimeError as e: |
|
|
|
|
|
|
|
print('Error mounting file system.') |
|
|
|
|
|
|
|
|
|
|
|
logging.info('Exiting.') |
|
|
|
logging.info('Exiting.') |
|
|
|
|
|
|
|
|
|
|
|