def download(self): """Downloads a file from the user's dropbox""" cwd = sh.get_cwd() + "/" parser = argparse.ArgumentParser( description="Download a file to the directory specified") parser.add_argument("file") parser.add_argument("dest", nargs="?", default=cwd) args = parser.parse_args(self.args[1:]) with self.stopwatch('download'): try: dbfile = util.file_path(self.curdir.get_directory(), args.file) destfile = util.file_path(args.dest, args.file) # user has specified local directory to save if not args.dest == cwd: self.dropbox.files_download_to_file( destfile.get_full_path(), dbfile.get_full_path()) print_succ( "file (%s) saved locally to %s " % (dbfile.get_full_path(), destfile.get_full_path())) else: # default to pwd of where sink was run self.dropbox.files_download_to_file( destfile.get_filename(), dbfile.get_full_path()) print_succ( "file (%s) saved locally to current directory %s" % (dbfile.get_full_path(), destfile.get_full_path())) except dropbox.exceptions.HttpError as err: print_error("sink download: could not download file") except dropbox.exceptions.ApiError as err: print_error("sink download: no such file")
def share(self): """Uploads a file to the users dropbox and prints a public link""" cwd = sh.get_cwd() + "/" parser = argparse.ArgumentParser( description="Uploads file to dropbox and returns a public link") parser.add_argument("--overwrite", action="store_true") parser.add_argument("file") args = parser.parse_args(self.args[1:]) mode = (dropbox.files.WriteMode.overwrite if args.overwrite else dropbox.files.WriteMode.add) try: local_file = util.file_path(cwd, args.file) dbx_file = util.file_path("/.sink/share/", args.file) with open(local_file.get_full_path(), "rb") as f: data = f.read() res = self.dropbox.files_upload(data, dbx_file.get_full_path()) print_succ("sink share: %s" % (self.dropbox.sharing_create_shared_link( dbx_file.get_full_path(), short_url=True).url)) except dropbox.exceptions.ApiError as e: print_error("sink share: could not share file")
def download(self): """Downloads a file from the user's dropbox""" cwd = sh.get_cwd() + "/" parser = argparse.ArgumentParser( description="Download a file to the directory specified") parser.add_argument("file") parser.add_argument("dest", nargs="?", default=cwd) args = parser.parse_args(self.args[1:]) with self.stopwatch('download'): try: dbfile = util.file_path(self.curdir.get_directory(), args.file) destfile = util.file_path(args.dest, args.file) # user has specified local directory to save if not args.dest == cwd: self.dropbox.files_download_to_file( destfile.get_full_path(), dbfile.get_full_path()) print_succ("file (%s) saved locally to %s " % (dbfile.get_full_path(), destfile.get_full_path())) else: # default to pwd of where sink was run self.dropbox.files_download_to_file( destfile.get_filename(), dbfile.get_full_path()) print_succ( "file (%s) saved locally to current directory %s" % (dbfile.get_full_path(), destfile.get_full_path())) except dropbox.exceptions.HttpError as err: print_error("sink download: could not download file") except dropbox.exceptions.ApiError as err: print_error("sink download: no such file")
def upload(self): """Uploads a file to the user's dropbox""" cwd = sh.get_cwd() + "/" parser = argparse.ArgumentParser(description="Uploads file to dropbox") parser.add_argument("--overwrite", action="store_true") parser.add_argument("file") parser.add_argument("path") args = parser.parse_args(self.args[1:]) mode = (dropbox.files.WriteMode.overwrite if args.overwrite else dropbox.files.WriteMode.add) try: local_file = util.file_path(cwd, args.file) dbx_file = util.file_path(args.path, args.file) with open(local_file.get_full_path(), "rb") as f: data = f.read() res = self.dropbox.files_upload(data, dbx_file.get_full_path()) print_succ("file %s uploaded to %s" % (local_file.get_filename(), dbx_file.get_full_path())) except dropbox.exceptions.ApiError as e: print_error("sink upload: could not upload file")