def download(self, remote_path, local_path=None): """Download a remote file to your machine.""" local_path = local_path or tempfile.mktemp( suffix=splitext(remote_path)[-1]) echo.debug('[DOWNLOAD] {0} => {1}'.format(remote_path, local_path)) self._client.download(self._to_real_path(remote_path), local_path) return local_path
def _launch_cli(client): """ NutStore Command Line Interface (0.4.1) NutStore WebDAV Settings: https://github.com/Kxrr/nutstore-cli/blob/master/docs/tutorial.md Project Page: https://github.com/Kxrr/nutstore-cli """ echo.debug('Client setup done') echo.info('Hello.'.format(client.username)) echo.info('Type "help" to see supported commands.') context = Context(client=client) history = InMemoryHistory() while True: try: text = prompt( message=u'[{path}] > '.format(path=context.path), completer=completer, history=history, auto_suggest=AutoSuggestFromHistory(), ) except EOFError: break else: execute(text, context) if context.should_exit: break echo.info('Goodbye.')
def upload(self, local_path, remote_dir=None): """Upload a local file to the remote(with the same filename)""" name = basename(local_path) directory = remote_dir or self.cwd remote_path = join(directory, name) echo.debug('[UPLOAD] {0} => {1}'.format(local_path, remote_path)) self._client.upload(local_path, self._to_real_path(remote_path)) return remote_path
def ls(self): def file_in_dir(filename, directory): filename = unquote(filename) return (directory in filename) and (filename != directory) real_path = self.np.real echo.debug('List "{}"'.format(real_path)) return filter(lambda f: file_in_dir(f.name, real_path), self._client.ls(real_path))
def __init__(self, prefix): self.config = {} for k in CONFIG_KEYS: env_key = '{prefix}{key}'.format(prefix=prefix, key=k).upper() v = getenv( env_key, self.NOT_SET ) if v is not self.NOT_SET: debug('Set "{}" to "{}" from environment variable {}'.format(k, v, env_key)) self.config[k] = v
def _main(ctx, username, key, working_dir): client = NutStoreClient(username=username, password=key, working_dir=working_dir, check_conn=False) echo.debug('Try to initial a client by given args') try: client.check_conn() except Exception as e: import traceback echo.error('Login failed, detail: {0}\n'.format( to_file(traceback.format_exc()))) import sys sys.exit(-1) else: ctx.obj['client'] = client
def load(self, filename): config = {} if not exists(filename): debug('Config file {} not exist'.format(filename)) return config debug('Loading config from {}'.format(filename)) with open(filename) as f: for line in f.readlines(): m = self.PARSE_RE.search(line) if m and (m.group(1).strip() in CONFIG_KEYS): k = m.group(1).strip() v = m.group(2).strip() debug('Set "{}" to "{}" in {}'.format(k, v, filename)) config[k] = v return config
def rm(self, remote_path): """Remove a file on the remote.""" echo.debug('[DELETE] {0}'.format(remote_path)) self._client.delete(self._to_real_path(remote_path)) return remote_path
def cd(self, directory): self.np.cd(directory) echo.debug('Change directory to "{}"'.format(self.np.real))