Example #1
0
 def login(self, uid: str = "", key: str = "", logout: bool = False):
     if logout:
         config = LoadConfig()
         config.loginId = None
         config.apiToken = None
         StoreConfig(config)
     else:
         if uid == "" or key == "":
             PrintError("You must have both uid and key to login.")
         else:
             config = LoadConfig()
             config.loginId = uid
             config.apiToken = key
             StoreConfig(config)
Example #2
0
def RemoveRepo(repoName: str) -> None:
    config = LoadConfig()
    try:
        config.repositoryPair.pop(repoName)
        StoreConfig(config)
    except KeyError:
        raise RepoNotExistsException(repoName)
Example #3
0
def SetRepoName(repoName: str, newName: str) -> None:
    config = LoadConfig()
    repoFolder = GetRepoFolderPath(repoName)
    if config.repositoryPair.__contains__(repoName):
        config.repositoryPair.pop(repoName)
        config.repositoryPair[newName] = repoFolder
        StoreConfig(config)
    else:
        raise RepoNotExistsException(repoName)
Example #4
0
 def rename(self, name: str, newname: str):
     config = LoadConfig()
     if name in config.repositoryPair.keys():
         folder = config.repositoryPair[name]
         config.repositoryPair.pop(name)
         config.repositoryPair[newname] = folder
         StoreConfig(config)
         print("Repo %s successfully renamed to %s" % (name, newname))
     else:
         PrintError("Repo \"%s\" not exists." % name)
         return
Example #5
0
 def chdir(self, name: str, newfolder: str):
     config = LoadConfig()
     if name in config.repositoryPair.keys():
         if path.exists(newfolder) and path.isdir(newfolder):
             folder = config.repositoryPair[name]
             config.repositoryPair[name] = newfolder
             StoreConfig()
             print(
                 "Update repo storage folder complete, please move all file from %s to %s"
                 % (folder, newfolder))
     else:
         PrintError("Repo \"%s\" not exists." % name)
         return
Example #6
0
def InitRepo(repoName: str, repoFolder: str, folderType: str,
             identifier: str) -> None:
    config = LoadConfig()
    summary = RepoSummary()
    summary.repoType = folderType
    summary.repoIdentifier = identifier
    summaryPath = repoFolder + REPO_SUMMARY_FILE_PATH
    # repo name or repo folder must be unique
    if (repoName in config.repositoryPair.keys()) or (
            repoFolder in config.repositoryPair.values()):
        raise RepoDuplicatedException(repoName, repoFolder)
    # make dir if this dir is not exists
    if not (os.path.exists(repoFolder) and os.path.isdir(repoFolder)):
        os.makedirs(repoFolder)
    # make summary.json if it is not exists
    if not (os.path.exists(summaryPath) and os.path.isfile(summaryPath)):
        StoreFile(summaryPath, json.dumps(dict(summary)))
    else:
        raise RepoDuplicatedException(repoName, repoFolder)
    config.repositoryPair[repoName] = repoFolder
    StoreConfig(config)
Example #7
0
 def _StoreConfig(self) -> None:
     StoreConfig(self._config)