Exemple #1
0
    def clear(self):
        """Clears the console"""
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(description="Clear the console")

        # this is how most terminals `clear`
        print(chr(27) + "[2J")
Exemple #2
0
    def clear(self):
        """Clears the console"""
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(description="Clear the console")

        # this is how most terminals `clear`
        print(chr(27) + "[2J")
Exemple #3
0
    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")
Exemple #4
0
    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")
Exemple #5
0
    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")
Exemple #6
0
    def execute(self):
        """Executes an external shell command"""
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(
            description="Executes an external shell command")
        parser.add_argument("cmd")

        try:
            sh.sh(self.args[1:])
        except:
            print(coloured("shell command not found", "red"))
Exemple #7
0
    def execute(self):
        """Executes an external shell command"""
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(
            description="Executes an external shell command")
        parser.add_argument("cmd")

        try:
            sh.sh(self.args[1:])
        except:
            print(coloured("shell command not found", "red"))
Exemple #8
0
    def execute(self):
        """Executes an external shell command

        returns whether or not the shell command executed successfully
        """
        cwd = sh.get_cwd() + "/"
        parser = argparse.ArgumentParser(
            description="Executes an external shell command")
        parser.add_argument("cmd")

        try:
            sh.sh(self.args[1:])
            return True
        except:
            print(coloured("shell command not found", "red"))
            return False
Exemple #9
0
    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")
Exemple #10
0
    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")
Exemple #11
0
    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")