Example #1
0
 def handle_item_creation(self, item, item_path):
     """
     When there is no record in database about the item, and the item does not exist locally, create the item
     locally and update the database.
     :param onedrive_d.api.items.OneDriveItem item:
     :param str item_path:
     """
     if item.is_folder:
         # If the item is a folder, create it and schedule a sync later.
         try:
             self.logger.debug(
                 'Creating directory "%s" as it does not exist locally and has no previous '
                 'record.', item_path)
             mkdir(item_path)
             parent_path = self.drive.drive_path + '/root:' if self.item_path is None else self.item_path
             self.items_store.update_item(item, parent_path=parent_path)
             self.task_pool.add_task(
                 SynchronizeDirTask(
                     self,
                     self.local_relative_parent_path + '/' + self.name,
                     item.name))
         except (IOError, OSError) as e:
             self.logger.error('Failed to create directory "%s": %s.',
                               item_path, e)
     else:
         # Just download the item.
         self.logger.debug(
             'Downloading "%s" as it does not exist locally and has no record in database.',
             item_path)
         self.task_pool.add_task(DownloadFileTask(self, item))
Example #2
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:
            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 e:
            puts(colored.red('Error: ' + str(e)))
    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)
Example #3
0
 def handle_item_creation(self, item, item_path):
     """
     When there is no record in database about the item, and the item does not exist locally, create the item
     locally and update the database.
     :param onedrive_d.api.items.OneDriveItem item:
     :param str item_path:
     """
     if item.is_folder:
         # If the item is a folder, create it and schedule a sync later.
         try:
             self.logger.debug('Creating directory "%s" as it does not exist locally and has no previous '
                               'record.', item_path)
             mkdir(item_path)
             self.items_store.update_item(item)
             self.task_pool.add_task(SynchronizeDirTask(self, self.local_relative_parent_path + '/' +
                                                        self.name, item.name))
         except (IOError, OSError) as e:
             self.logger.error('Failed to create directory "%s": %s.', item_path, e)
     else:
         # Just download the item.
         self.logger.debug('Downloading "%s" as it does not exist locally and has no record in database.',
                           item_path)
         self.task_pool.add_task(DownloadFileTask(self, item))
Example #4
0
import os
import sys

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

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

try:
    if not os.path.exists(CONFIG_DIR):
        mkdir(CONFIG_DIR)
        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)


def add_personal_account():
    puts(colored.green('Link with an OneDrive Personal account:'))
Example #5
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:
            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 e:
            puts(colored.red('Error: ' + str(e)))
    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)
Example #6
0
import os
import sys

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

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

try:
    if not os.path.exists(CONFIG_DIR):
        mkdir(CONFIG_DIR)
        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)