예제 #1
0
def prompt_drive_config(drive):
    if hasattr(drive, 'config'):
        drive_config_data = drive.config.data
    else:
        drive_config_data = drive_config.DriveConfig.DEFAULT_VALUES
    if drive_config_data['local_root'] is None or drive_config_data['local_root'] == '':
        drive_config_data['local_root'] = OS_USER_HOME + '/OneDrive/' + drive.drive_id
    puts(colored.green('You selected Drive "%s"...' % drive.drive_id))

    puts()
    with indent(4, quote=' >'):
        puts('When specifying local root, pick a directory not used by or under any other Drive.')
        puts('When specifying HTTPS download / upload sizes, note that files larger than those sizes will be handled '
             'as chunks.')
    puts()

    while True:
        local_root = prompt.query('Which local directory do you want to sync with this Drive?',
                                  default=drive_config_data['local_root'])
        try:
            while local_root[-1] == '/':
                local_root = local_root[:-1]
            if not os.path.exists(local_root):
                puts(colored.yellow('Directory "%s" does not exist. Try creating it...' % local_root))
                mkdir(local_root)
                puts(colored.green('Successfully created directory "%s".' % local_root))
            elif os.path.isfile(local_root):
                raise ValueError('Path "%s" is a file.' % local_root)
            if os.path.isdir(local_root):
                drive_config_data['local_root'] = local_root
                break
            raise ValueError('Invalid path "%s"' % local_root)
        except Exception as ex:
            puts(colored.red('Error: ' + str(ex)))
    drive_config_data['max_get_size_bytes'] = prompt.query('Maximum size, in KB, for a single download request?',
                                                           default=str(drive_config_data['max_get_size_bytes'] >> 10),
                                                           validators=[validators.IntegerValidator()]) * 1024
    drive_config_data['max_put_size_bytes'] = prompt.query('Maximum size, in KB, for a single upload request?',
                                                           default=str(drive_config_data['max_put_size_bytes'] >> 10),
                                                           validators=[validators.IntegerValidator()]) * 1024
    try:
        while not prompt.yn('Do you have ignore list files specific to this Drive to add?', default='n'):
            ignore_file_path = prompt.query('Path to the ignore list file (hit [Ctrl+C] to skip): ',
                                            validators=[validators.FileValidator()])
            drive_config_data['ignore_files'].add(ignore_file_path)
            puts(colored.green('Recorded ignore list file: "{}"' % ignore_file_path))
    except KeyboardInterrupt:
        pass
    drive_conf = drive_config.DriveConfig.load(drive_config_data)
    drive.config = drive_conf
    drive_store.add_record(drive)
예제 #2
0
 def _create_download_task(self, item_local_path, item):
     """
     Create a new directory or download the file.
     :param str item_local_path:
     :param onedrived.api.items.OneDriveItem item:
     """
     if item.is_folder:
         try:
             self.logger.info('Creating directory "%s".', item_local_path)
             mkdir(item_local_path)
             self.items_store.update_item(item, ItemRecordStatuses.OK)
             self._create_merge_dir_task(item.name, item)
         except (OSError, IOError) as e:
             self.logger.error('Error creating directory "%s": %s.', item_local_path, e)
     else:
         if not self.task_pool.has_pending_task(item_local_path):
             self.logger.info('Will download file "%s".', item_local_path)
             self.task_pool.add_task(DownloadFileTask(self, rel_parent_path=self.rel_path + '/', item=item))
예제 #3
0
 def _create_download_task(self, item_local_path, item):
     """
     Create a new directory or download the file.
     :param str item_local_path:
     :param onedrived.api.items.OneDriveItem item:
     """
     if item.is_folder:
         try:
             self.logger.info('Creating directory "%s".', item_local_path)
             mkdir(item_local_path)
             self.items_store.update_item(item, ItemRecordStatuses.OK)
             self._create_merge_dir_task(item.name, item)
         except (OSError, IOError) as e:
             self.logger.error('Error creating directory "%s": %s.',
                               item_local_path, e)
     else:
         if not self.task_pool.has_pending_task(item_local_path):
             self.logger.info('Will download file "%s".', item_local_path)
             self.task_pool.add_task(
                 DownloadFileTask(self,
                                  rel_parent_path=self.rel_path + '/',
                                  item=item))
예제 #4
0
def prompt_drive_config(drive):
    if hasattr(drive, "config"):
        drive_config_data = drive.config.data
    else:
        drive_config_data = drive_config.DriveConfig.DEFAULT_VALUES
    if drive_config_data["local_root"] is None or drive_config_data["local_root"] == "":
        drive_config_data["local_root"] = OS_USER_HOME + "/OneDrive/" + drive.drive_id
    puts(colored.green('You selected Drive "%s"...' % drive.drive_id))

    puts()
    with indent(4, quote=" >"):
        puts("When specifying local root, pick a directory not used by or under any other Drive.")
        puts(
            "When specifying HTTPS download / upload sizes, note that files larger than those sizes will be handled "
            "as chunks."
        )
    puts()

    while True:
        local_root = prompt.query(
            "Which local directory do you want to sync with this Drive?", default=drive_config_data["local_root"]
        )
        try:
            while local_root[-1] == "/":
                local_root = local_root[:-1]
            if not os.path.exists(local_root):
                puts(colored.yellow('Directory "%s" does not exist. Try creating it...' % local_root))
                mkdir(local_root)
                puts(colored.green('Successfully created directory "%s".' % local_root))
            elif os.path.isfile(local_root):
                raise ValueError('Path "%s" is a file.' % local_root)
            if os.path.isdir(local_root):
                drive_config_data["local_root"] = local_root
                break
            raise ValueError('Invalid path "%s"' % local_root)
        except Exception as ex:
            puts(colored.red("Error: " + str(ex)))
    drive_config_data["max_get_size_bytes"] = (
        prompt.query(
            "Maximum size, in KB, for a single download request?",
            default=str(drive_config_data["max_get_size_bytes"] >> 10),
            validators=[validators.IntegerValidator()],
        )
        * 1024
    )
    drive_config_data["max_put_size_bytes"] = (
        prompt.query(
            "Maximum size, in KB, for a single upload request?",
            default=str(drive_config_data["max_put_size_bytes"] >> 10),
            validators=[validators.IntegerValidator()],
        )
        * 1024
    )
    try:
        while not prompt.yn("Do you have ignore list files specific to this Drive to add?", default="n"):
            ignore_file_path = prompt.query(
                "Path to the ignore list file (hit [Ctrl+C] to skip): ", validators=[validators.FileValidator()]
            )
            drive_config_data["ignore_files"].add(ignore_file_path)
            puts(colored.green('Recorded ignore list file: "{}"' % ignore_file_path))
    except KeyboardInterrupt:
        pass
    drive_conf = drive_config.DriveConfig.load(drive_config_data)
    drive.config = drive_conf
    drive_store.add_record(drive)
예제 #5
0
import os
import sys

from clint.textui import colored, columns, indent, prompt, puts, validators

from onedrived import OS_USER_NAME, OS_USER_HOME, mkdir, get_content
from onedrived.api import accounts, clients
from onedrived.cli import CONFIG_DIR, get_current_user_config
from onedrived.common import drive_config, netman
from onedrived.store import account_db, drives_db
from onedrived.vendor.utils import pretty_print_bytes

try:
    if not os.path.exists(CONFIG_DIR):
        mkdir(CONFIG_DIR)
        default_ignore_list_data = get_content("default_ignore_list.txt", is_text=True)
        with open(CONFIG_DIR + "/odignore.txt", "w") as f:
            f.write(default_ignore_list_data)
        print(colored.green('Created path "' + CONFIG_DIR + '".'))
    user_conf = get_current_user_config()
    network_monitor = netman.NetworkMonitor()
    personal_client = clients.PersonalClient(proxies=user_conf.proxies, net_monitor=network_monitor)
    business_client = None
    account_store = account_db.AccountStorage(
        CONFIG_DIR + "/accounts.db", personal_client=personal_client, business_client=business_client
    )
    drive_store = drives_db.DriveStorage(CONFIG_DIR + "/drives.db", account_store)
except Exception as e:
    print(colored.red("Fatal error: " + str(e)))
    sys.exit(1)
예제 #6
0
import os
import sys

from clint.textui import colored, columns, indent, prompt, puts, validators

from onedrived import OS_USER_NAME, OS_USER_HOME, mkdir, get_content
from onedrived.api import accounts, clients
from onedrived.cli import CONFIG_DIR, get_current_user_config
from onedrived.common import drive_config, netman
from onedrived.store import account_db, drives_db
from onedrived.vendor.utils import pretty_print_bytes

try:
    if not os.path.exists(CONFIG_DIR):
        mkdir(CONFIG_DIR)
        default_ignore_list_data = get_content('default_ignore_list.txt', is_text=True)
        with open(CONFIG_DIR + '/odignore.txt', 'w') as f:
            f.write(default_ignore_list_data)
        print(colored.green('Created path "' + CONFIG_DIR + '".'))
    user_conf = get_current_user_config()
    network_monitor = netman.NetworkMonitor()
    personal_client = clients.PersonalClient(proxies=user_conf.proxies, net_monitor=network_monitor)
    business_client = None
    account_store = account_db.AccountStorage(
            CONFIG_DIR + '/accounts.db', personal_client=personal_client, business_client=business_client)
    drive_store = drives_db.DriveStorage(CONFIG_DIR + '/drives.db', account_store)
except Exception as e:
    print(colored.red('Fatal error: ' + str(e)))
    sys.exit(1)