def run(self):
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit()
     HfFolder.delete_token()
     self._api.logout(token)
     print("Successfully logged out.")
    def run(self):
        token = HfFolder.get_token()
        if token is None:
            print("Not logged in")
            exit(1)

        user, _ = self._api.whoami(token)
        namespace = self.args.organization if self.args.organization is not None else user

        local_path = os.path.abspath(self.args.path)
        if os.path.isdir(local_path):
            if self.args.filename is not None:
                raise ValueError("Cannot specify a filename override when uploading a folder.")
            rel_path = os.path.basename(local_path)
            files = self.walk_dir(rel_path)
        elif os.path.isfile(local_path):
            filename = self.args.filename if self.args.filename is not None else os.path.basename(local_path)
            files = [(local_path, filename)]
        else:
            raise ValueError("Not a valid file or directory: {}".format(local_path))

        if sys.platform == "win32":
            files = [(filepath, filename.replace(os.sep, "/")) for filepath, filename in files]

        if len(files) > UPLOAD_MAX_FILES:
            print(
                "About to upload {} files to S3. This is probably wrong. Please filter files before uploading.".format(
                    ANSI.bold(len(files))
                )
            )
            exit(1)

        for filepath, filename in files:
            print(
                "About to upload file {} to S3 under filename {} and namespace {}".format(
                    ANSI.bold(filepath), ANSI.bold(filename), ANSI.bold(namespace)
                )
            )

        choice = input("Proceed? [Y/n] ").lower()
        if not (choice == "" or choice == "y" or choice == "yes"):
            print("Abort")
            exit()
        print(ANSI.bold("Uploading... This might take a while if files are large"))
        for filepath, filename in files:
            try:
                access_url = self._api.presign_and_upload(
                    token=token, filename=filename, filepath=filepath, organization=self.args.organization
                )
            except HTTPError as e:
                print(e)
                print(ANSI.red(e.response.text))
                exit(1)
            print("Your file now lives at:")
            print(access_url)
 def run(self):
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit(1)
     try:
         self._api.delete_obj(token, filename=self.args.filename, organization=self.args.organization)
     except HTTPError as e:
         print(e)
         print(ANSI.red(e.response.text))
         exit(1)
     print("Done")
Beispiel #4
0
    def run(self):
        print("""
        _|    _|  _|    _|    _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|_|_|_|    _|_|      _|_|_|  _|_|_|_|
        _|    _|  _|    _|  _|        _|          _|    _|_|    _|  _|            _|        _|    _|  _|        _|
        _|_|_|_|  _|    _|  _|  _|_|  _|  _|_|    _|    _|  _|  _|  _|  _|_|      _|_|_|    _|_|_|_|  _|        _|_|_|
        _|    _|  _|    _|  _|    _|  _|    _|    _|    _|    _|_|  _|    _|      _|        _|    _|  _|        _|
        _|    _|    _|_|      _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|        _|    _|    _|_|_|  _|_|_|_|

        """)
        username = input("Username: "******"Login successful")
        print("Your token:", token, "\n")
        print("Your token has been saved to", HfFolder.path_token)
Beispiel #5
0
 def run(self):
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit()
     try:
         user, orgs = self._api.whoami(token)
         print(user)
         if orgs:
             print(ANSI.bold("orgs: "), ",".join(orgs))
     except HTTPError as e:
         print(e)
 def run(self):
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit(1)
     try:
         objs = self._api.list_objs(token, organization=self.args.organization)
     except HTTPError as e:
         print(e)
         print(ANSI.red(e.response.text))
         exit(1)
     if len(objs) == 0:
         print("No shared file yet")
         exit()
     rows = [[obj.filename, obj.LastModified, obj.ETag, obj.Size] for obj in objs]
     print(self.tabulate(rows, headers=["Filename", "LastModified", "ETag", "Size"]))