Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
#17: Add from_local_config and from_cloud_config on LocalDriveConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
derrix060 committed Sep 28, 2018
1 parent db5e19c commit eae678f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
13 changes: 10 additions & 3 deletions onedrived/od_models/drive_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from collections import namedtuple
class LocalDriveConfig:
"""Configuration for the local drive. This is saved on UserContext.DEFAULT_CONFIG_FILENAME."""


LocalDriveConfig = namedtuple('LocalDriveConfig', ('drive_id', 'account_id', 'ignorefile_path', 'localroot_path'))
def __init__(self, drive_id, account_id, ignorefile_path, localroot_path,
from_local_config='dmn', from_cloud_config='dmn'):
self.drive_id = drive_id
self.account_id = account_id
self.ignorefile_path = ignorefile_path
self.localroot_path = localroot_path
self.from_local_config = from_local_config
self.from_cloud_config = from_cloud_config
68 changes: 59 additions & 9 deletions onedrived/od_pref.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def list_drives():


def local_root_path(curr_drive_config):
"""Get the root path to sync the drive."""
if curr_drive_config:
default = curr_drive_config.localroot_path
else:
Expand Down Expand Up @@ -341,6 +342,7 @@ def local_root_path(curr_drive_config):


def ignore_file_path(curr_drive_config):
"""Get the path to find the configuration to ignore files."""
if curr_drive_config:
default = curr_drive_config.ignorefile_path
else:
Expand All @@ -357,14 +359,55 @@ def ignore_file_path(curr_drive_config):
return ignore_file


def from_local_configuration(curr_drive_config):
"""Get the operations that will be performed from local to the cloud."""
if getattr(curr_drive_config, 'from_local_config', None):
default = curr_drive_config.from_local_config
else:
default = 'dmn'

return click.prompt(
'Type the operations that you want to enable to perform from local'
' (from local to OneDrive), for example if you delete a local content '
' and the "d" configuration is set, this content will be deleted on '
' the OneDrive too. Use "d" for delete, "m" for move and rename'
' "n" for new. You can set more than one option, for example: "dmn"'
' for delete + move + new.',
default=default)


def from_cloud_configuration(curr_drive_config):
"""Get the operations that will be performed from the cloud to local."""
if getattr(curr_drive_config, 'from_cloud_config', None):
default = curr_drive_config.from_cloud_config
else:
default = 'dmn'

return click.prompt(
'Type the operations that you want to enable to perform from cloud'
' (from OneDrive to local), for example if you delete a content on'
' OneDrive, and the "d" configuration is set, this content'
' will be deleted locally too. Use "d" for delete, "m" for move and rename'
' "n" for new. You can set more than one option, for example: "dmn"'
' for delete + move + new.',
default=default)


@click.command(name='set')
@click.option('--drive-id', '-d', help='ID of the Drive.')
@click.option('--email', '-e', help='Email of an authorized account.')
@click.option('--local-root', type=click.Path(),
help='Local directory to sync with the Drive.')
@click.option('--ignore-file', type=click.Path(),
help='File that contains path patterns to ignore when syncing.')
def set_drive(drive_id=None, email=None, local_root=None, ignore_file=None):
@click.option('--ignore-file', type=click.Path(),
help='File that contains path patterns to ignore when syncing.')
@click.option('--from-local-config', help=(
'Configuration that will be performed from local to the cloud. Example: "dmn"'))
@click.option('--from-cloud-config', help=(
'Configuration that will be performed locally from the cloud. Example: "dmn"'))
def set_drive(drive_id=None, email=None, local_root=None, ignore_file=None,
from_local_config=None, from_cloud_config=None):
"""Add or modify a remote drive to sync with local directory."""
all_drives, drive_table = print_all_drives()
click.echo()
Expand Down Expand Up @@ -392,17 +435,24 @@ def set_drive(drive_id=None, email=None, local_root=None, ignore_file=None):
f'Going to add/edit Drive "{drive_id}"'
f' of account "{acc_profile.account_email}"...', fg='cyan'))
# Get local_root.
local_root = local_root_path(curr_drive_config)
local_root = local_root or local_root_path(curr_drive_config)
# Get ignore_file.
ignore_file = ignore_file_path(curr_drive_config)

d = context.add_drive(drive_config.LocalDriveConfig(
drive_id, account_id, ignore_file, local_root))
ignore_file = ignore_file or ignore_file_path(curr_drive_config)
# Get upload configuration.
from_local_config = from_local_config or from_local_config_configuration(curr_drive_config)
# Get download configuration.
from_cloud_config = from_cloud_config or from_cloud_config_configuration(curr_drive_config)

drive = context.add_drive(drive_config.LocalDriveConfig(
drive_id, account_id, ignore_file, local_root, from_local_config,
from_cloud_config))
save_context(context)
success('\nSuccessfully configured Drive %s of account %s (%s):' % (
d.drive_id, acc_profile.account_email, d.account_id))
click.echo(' Local directory: ' + d.localroot_path)
click.echo(' Ignore file path: ' + d.ignorefile_path)
drive.drive_id, acc_profile.account_email, drive.account_id))
click.echo(' Local directory: ' + drive.localroot_path)
click.echo(' Ignore file path: ' + drive.ignorefile_path)
click.echo(' From local config: ' + drive.from_local_config)
click.echo(' From cloud config: ' + drive.from_cloud_config)


@click.command(name='del', short_help=translator['od_pref.del_drive.short_help'])
Expand Down

0 comments on commit eae678f

Please sign in to comment.