Esempio n. 1
0
    def publishTheGivenTag(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        pOpenCommandList = ["git", "tag"]
        status = utils().popenTask(pOpenCommandList)
        output = status[0]
        output = output.split('\n')
        tagList = utils().removeSpaceAndSpecialCharFromList(output)

        for tag in tagList:
            if(tag == args.deploy_bitbucket_tag):
                pOpenCommandList = ["git", "ls-remote", "origin", "refs/tags/" + tag]
                status = utils().popenTask(pOpenCommandList)
                output = status[0]
                
                self.excludeFiles(args, tag)

                if(not output):
                    pOpenCommandList = ["git", "push", "origin", tag]
                    status = utils().popenTask(pOpenCommandList)
                    output = status[0]
                    print("[*] pushing tag " + tag + " to remote Github repo")
                else:
                    print("[-] Tag: " + tag + " is already present in the remote Github repo")

            else:
                print("[*] Tag: " + tag + " is not present in the cloned bitbucket repository")
Esempio n. 2
0
    def createRepo(self, args, githubAccess):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: Boolean
        """

        print("[*] Creating a repository...")

        githubAccessHook = self.organizationRepoAccessGet(args, githubAccess)

        if (args.repo_organization):
            print("[*] Creating a repository in the selected organization")

        if (not args.repo_desc):
            args.repo_desc = ""

        try:
            githubAccessHook.create_repo(name=args.repo_name,
                                         description=args.repo_desc,
                                         has_issues=args.repo_has_issues,
                                         has_projects=args.repo_has_projects,
                                         private=args.repo_private)

            return True
        except Exception as e:
            if (args.debug_mode):
                print("[Debug] createRepo: " + str(e))

            utils().githubExceptionWarningMessage(str(e))
            utils().githubExceptionErrorMessage(str(e))
            status = utils().errorMsgPrintForhttpStatusCode(args, str(e))
            if (status):
                raise Exception("")
Esempio n. 3
0
    def publishInternalReleaseTags(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        # Push all the public release tags to Github
        pOpenCommandList = ["git", "tag"]
        status = utils().popenTask(pOpenCommandList)
        output = status[0]
        output = output.split('\n')
        tagList = utils().removeSpaceAndSpecialCharFromList(output)

        for tag in tagList:
            if(tag.upper().find("RC") > -1):
                pOpenCommandList = ["git", "ls-remote", "origin", "refs/tags/" + tag]
                status = utils().popenTask(pOpenCommandList)
                output = status[0]
                
                self.excludeFilesForTag(args, tag)

                if(not output):
                    pOpenCommandList = ["git", "push", "origin", tag]
                    status = utils().popenTask(pOpenCommandList)
                    output = status[0]
                    print("[*] pushing tag " + tag + " to remote Github repo")
                else:
                    print("[-] Tag: " + tag + " is already present in the remote Github repo")
            else:
                print("[-] Tag:" + tag + " isn't a internal release tag.")
Esempio n. 4
0
    def publishAllTags(self, args):
        """
        :type: None
        """

        # Push all the tags to Github
        pOpenCommandList = ["git", "tag"]
        status = utils().popenTask(pOpenCommandList)
        output = status[0]
        output = output.split('\n')
        tagList = utils().removeSpaceAndSpecialCharFromList(output)

        for tag in tagList:
            pOpenCommandList = ["git", "ls-remote", "origin", "refs/tags/" + tag]
            status = utils().popenTask(pOpenCommandList)
            output = status[0]

            self.excludeFilesForTag(args, tag)
            
            if(not output):
                pOpenCommandList = ["git", "push", "origin", tag]
                status = utils().popenTask(pOpenCommandList)
                output = status[0]
                print("[*] pushing tag " + tag + " to remote Github repo")
            else:
                print("[-] Tag: " + tag + " is already present in the remote Github repo")
Esempio n. 5
0
    def updateRepoTopics(self, args, githubAccess):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: None
        """

        githubAccessHook = self.organizationRepoAccessGet(args, githubAccess)

        if (args.repo_organization):
            print(
                "[*] Updating a repository topics in the selected organization"
            )

        repoList = []
        findRepoStatus = False

        for repo in githubAccessHook.get_repos():

            # Check repo name
            if (args.repo_name == repo.name):
                print("[*] Updating repository topics...")
                findRepoStatus = True
                repoList.append(repo.full_name)
                args.repo_topics = args.repo_topics.replace("[", "").replace(
                    "]", "").replace('"', '')
                topicsList = args.repo_topics.split(',')
                topicsList = self.validateRepoTopics(topicsList)

                # converting lower case
                topicsList = [x.lower() for x in topicsList]

                if (args.debug_mode):
                    print("[ Debug] topicsList: ")
                    print(topicsList)

                try:
                    repo.replace_topics(topicsList)
                except Exception as e:
                    utils().githubExceptionWarningMessage(str(e))
                    utils().githubExceptionErrorMessage(str(e))
                    status = utils().errorMsgPrintForhttpStatusCode(
                        args, str(e))
                    if (status):
                        raise Exception("")

        if (repoList):
            print("[*] Updated github repository topics into : " +
                  str(repoList))

        if (findRepoStatus == False):
            raise Exception("[!] Unable to find github repository name: " +
                            args.repo_name)
        return None
Esempio n. 6
0
    def cloneRepository(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        if(args.deploy_bitbucket_url and not args.deploy_bitbucket_repo_folder):
            # Clone Git repository
            pOpenCommandList = ["git", "clone",  args.deploy_bitbucket_url, self.workSpaceFolder]
            utils().popenTask(pOpenCommandList)
        else:
            # Copy Git repository
            utils().copytree(args.deploy_bitbucket_repo_folder, self.workSpaceFolder)
        pass 
Esempio n. 7
0
    def performDeployOperations(self, args, githubAccess):
        """
        :param args: command line input arguments
        :type: None
        """

        # --deployment
        # --deploy_bitbucket_url
        # --deploy_github_url
        # --deploy_github_user_id
        # --deploy_bitbucket_branch
        # --deploy_bitbucket_tag

        privateRepoStatus = False

        githubAccessHook = self.gitHubAccessGet(args, githubAccess)
        privateRepoStatus = self.getRepoPrivateAccessStatus(args, githubAccessHook)

        if(privateRepoStatus):
            self.updatePublicRepo(args, githubAccessHook)

        print("[*] Starting deployment process at " + utils().currentDataAndTimeGet())

        try:
            self.createWorkSpace()
            self.cloneRepository(args)
            os.chdir(self.workSpaceFolder)
            
            if(args.debug_mode):
                print("[Debug] performDeployOperations->cwd: " +  str(os.getcwd()))

            # Publishing branch
            for branch in args.deploy_bitbucket_branch:
                if(args.debug_mode):
                    print("[Debug] performDeployOperations->branch: " + branch)

                self.checkoutBranch(args, branch)
                if(not args.deploy_mandatory_files_check_disable):
                    utils().isRepoMandatoryFilesArePresent("./", branch)
                self.publishBranch(args, branch)

            # Publishing Tags
            self.publishTags(args)

            if(privateRepoStatus):
                self.updatePrivateRepo(args, githubAccessHook)
        except Exception as e:
            if(privateRepoStatus):
                self.updatePrivateRepo(args, githubAccessHook)
            raise Exception(e)
Esempio n. 8
0
    def organizationRepoAccessGet(self, args, githubAccess):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: GitHub interface
        """

        try:
            if (args.repo_organization):
                return githubAccess.get_organization(args.repo_organization)
            return githubAccess.get_user()
        except Exception as e:
            utils().githubExceptionWarningMessage(str(e))
            utils().githubExceptionErrorMessage(str(e))
            pass
Esempio n. 9
0
    def publishTags(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        INTERNAL_RELEASE_TAGS="internal"
        PUBLIC_RELEASE_TAGS="public"
        ALL_TAGS="all"
        pattern = re.compile("^(.*?)\.(.*?)\..*$")

        if(args.deploy_bitbucket_tag):
            if(utils().checkSemanticVersioningRegex(args.deploy_bitbucket_tag)):
                if args.debug_mode: print("[Debug] publishTags->checkSemanticVersioningRegex : " + args.deploy_bitbucket_tag)
                self.publishTheGivenTag(args)
            elif(args.deploy_bitbucket_tag == INTERNAL_RELEASE_TAGS):
                if args.debug_mode: print("[Debug] publishTags->publishInternalReleaseTags : " + args.deploy_bitbucket_tag)
                self.publishInternalReleaseTags(args)
            elif(args.deploy_bitbucket_tag == PUBLIC_RELEASE_TAGS):
                if args.debug_mode: print("[Debug] publishTags->publishAllPublicReleaseTags : " + args.deploy_bitbucket_tag)
                self.publishAllPublicReleaseTags(args)
            elif(args.deploy_bitbucket_tag == ALL_TAGS):
                if args.debug_mode: print("[Debug] publishTags->publishAllTags : " + args.deploy_bitbucket_tag)
                self.publishAllTags(args)
            elif(pattern.match(args.deploy_bitbucket_tag)):
                if args.debug_mode: print("[Debug] publishTags->publishRegexMatchedTags : " + args.deploy_bitbucket_tag)
                self.publishRegexMatchedTags(args)
        else:
            if(not args.deploy_ignore_default_all_tags_push):
                if args.debug_mode: print("[Debug] publishTags->publishAllPublicReleaseTags : " + str(args.deploy_bitbucket_tag))
                self.publishAllPublicReleaseTags(args)
Esempio n. 10
0
    def validateURLPath(self, args):
        """
        :param args: command line input arguments
        :type: None
        """
        exceptionString = ""

        if(args.deployment):

            if(args.deploy_bitbucket_url and not args.deploy_bitbucket_repo_folder):
                if(args.debug_mode):
                    print("[Debug] Bitbucket URL: " + args.deploy_bitbucket_url)
                    print("[Debug] GitHub URL: " + args.deploy_github_url)

                if(args.deploy_bitbucket_url.find(".git") > -1):
                    if(not utils().checkIsGitRepoExists(args.deploy_bitbucket_url)):
                        exceptionString += ("[!] Invalid deploy_bitbucket_url path: " + args.deploy_bitbucket_url)
                else:
                    exceptionString += ("[!] Invalid deploy_bitbucket_url path: " + args.deploy_bitbucket_url)
        
            if(args.deploy_github_url):
                gitHubUrl = "https://" + args.deploy_github_user_id + ":"+ args.github_personal_access_token +"@" + args.deploy_github_url.replace("https://","")
                args.deploy_github_url = gitHubUrl

        if(exceptionString):
            raise Exception (exceptionString)
Esempio n. 11
0
    def updateRepo(self, args, githubAccess):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: Boolean
        """

        print("[*] Updating a repository...")

        githubAccessHook = self.organizationRepoAccessGet(args, githubAccess)

        if (args.repo_organization):
            print("[*] Updating a repository in the selected organization")

        try:
            for repo in githubAccessHook.get_repos():
                # Check repo name
                if (args.repo_name == repo.name):
                    if (args.repo_desc == None):
                        repo.edit(
                            has_issues=args.repo_has_issues,
                            has_projects=args.repo_has_projects,
                            private=args.repo_private,
                        )
                    else:
                        repo.edit(
                            description=args.repo_desc,
                            has_issues=args.repo_has_issues,
                            has_projects=args.repo_has_projects,
                            private=args.repo_private,
                        )

                    if (args.repo_default_branch):
                        self.updateDefaultBranch(args, repo)

            return True
        except Exception as e:
            if (args.debug_mode):
                print("[Debug] createRepo: " + str(e))

            utils().githubExceptionWarningMessage(str(e))
            utils().githubExceptionErrorMessage(str(e))
            status = utils().errorMsgPrintForhttpStatusCode(args, str(e))
            if (status):
                raise Exception("")
Esempio n. 12
0
    def excludeFiles(self, args, branch):
        """
        :param args: command line input arguments
        :param branch: git branch name
        :type: None
        """

        if(args.deploy_excludes_files):
            print("[*] Excluding files...")
            excludeFileList = args.deploy_excludes_files.split(',')

            for excludeFile in excludeFileList:
                excludeFile = excludeFile.replace(" ", "")
                utils().purge('.', excludeFile)

            if(args.debug_mode):        
                pOpenCommandList = ["git", "status"]
                status = utils().popenTask(pOpenCommandList)
                print("[ Debug mode ] Git status: " + str(status))

            pOpenCommandList = ["git", "add", "-A"]
            status = utils().popenTask(pOpenCommandList)
        
            if(args.deploy_excludes_files_commit):
                pOpenCommandList = ["git", "commit", "-m", args.deploy_excludes_files_commit]
                status = utils().popenTask(pOpenCommandList)
            else:
                pOpenCommandList = ["git", "commit", "-m", "Merging into the " + branch + " branch"]
                status = utils().popenTask(pOpenCommandList)

            if(args.debug_mode):        
                pOpenCommandList = ["git", "status"]
                status = utils().popenTask(pOpenCommandList)
                print("[ Debug mode ] Git status: " + str(status))
Esempio n. 13
0
    def updateDefaultBranch(self, args, repo):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: Boolean
        """

        print("[*] Updating a repository default branch...")

        try:
            repo.edit(default_branch=args.repo_default_branch)

            return True
        except Exception as e:
            utils().githubExceptionWarningMessage(str(e))
            utils().githubExceptionErrorMessage(str(e))
            status = utils().errorMsgPrintForhttpStatusCode(args, str(e))
            if (status):
                raise Exception("")
Esempio n. 14
0
    def checkoutBranch(self, args, branch):
        """
        :param args: command line input arguments
        :param branch: Bitbucket branch name
        :type: None
        """

        # ensure we checkout the given branch
        pOpenCommandList = ["git", "checkout", "--track", "origin/" + branch]
        status = utils().popenTask(pOpenCommandList)

        error = status[1]

        if(error.find("already exists") > -1):
            pOpenCommandList = ["git", "checkout", branch]
            utils().popenTask(pOpenCommandList)

    
        pOpenCommandList = ["git", "remote", "set-url", "origin", args.deploy_github_url]
        utils().popenTask(pOpenCommandList)
Esempio n. 15
0
 def validateGitBranch(self, args):
     """
     :param args: command line input arguments
     :type: None
     """
     
     if(not args.deploy_bitbucket_branch):
         args.deploy_bitbucket_branch = ["master"]
     else:
         args.deploy_bitbucket_branch = args.deploy_bitbucket_branch.split(',')
         args.deploy_bitbucket_branch = utils().removeSpaceAndSpecialCharFromList(args.deploy_bitbucket_branch)
     pass
Esempio n. 16
0
    def publishAllPublicReleaseTags(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        # Push all the public release tags to Github
        pOpenCommandList = ["git", "tag"]
        status = utils().popenTask(pOpenCommandList)
        output = status[0]
        output = output.split('\n')
        tagList = utils().removeSpaceAndSpecialCharFromList(output)

        for tag in tagList:
            if(utils().checkSemanticVersioningRegex(tag)):
                pOpenCommandList = ["git", "ls-remote", "origin", "refs/tags/" + tag]
                status = utils().popenTask(pOpenCommandList)
                output = status[0]

                self.excludeFilesForTag(args, tag)

                if(not output):
                    pOpenCommandList = ["git", "push", "origin", tag]
                    utils().popenTask(pOpenCommandList)
                    print("[*] pushing tag " + tag + " to remote Github repo")
                else:
                    print("[-] Tag: " + tag + " is already present in the remote Github repo")

            else:
                print("[-] " + tag + " isn't a public release or does not match the SEMVER pattern.")
Esempio n. 17
0
    def getRepoPrivateAccessStatus(self, args, githubAccessHook):
        """
        :param args: command line input arguments
        :githubAccessHook: GitHub interface
        :type: Repository private access status
        """

        try:
            repoName = utils().repositoryNameGet(args.deploy_github_url)
            repo = githubAccessHook.get_repo(repoName)
            return repo.private
        except Exception as e:
            raise Exception("[!] Invalid Github repository URL")
Esempio n. 18
0
 def gitHubAccessGet(self, args, githubAccess):
     try:
         githubAccessHook = repo().organizationRepoAccessGet(args, githubAccess)
         self.getRepoPrivateAccessStatus(args, githubAccessHook)
         return githubAccessHook
     except Exception as e:
         try:
             args.repo_organization = utils().organizationNameGet(args.deploy_github_url)
             githubAccessHook = repo().organizationRepoAccessGet(args, githubAccess)
             self.getRepoPrivateAccessStatus(args, githubAccessHook)
             return githubAccessHook
         except Exception as e:
             raise Exception("[!] Invalid GitHub repository URL")
Esempio n. 19
0
    def create_tag(self, args, gitAccess):
        if (self.getRepo(args, gitAccess)):
            try:
                tagList = self.bitbucketRepoTagListGet(args, gitAccess)

                if (self.isTagExists(args, tagList)):
                    print("[-] Tag already exists: " + str(tagList))
                    return

                gitAccess.set_tag(args.bitbucket_project_name, args.repo_name,
                                  args.bitbucket_tag_name,
                                  args.bitbucket_commit_hash,
                                  args.bitbucket_tag_description)
            except Exception as e:
                utils().errorMsgPrintForhttpStatusCode(args, str(e))
                raise Exception(
                    "[!] Either \"invalid Bitbucket repository commit hash\" or \"Repository name or Project name does not exists\" or \"Unauthorized Repository\""
                )
        else:
            raise Exception(
                "[!] Repository name or Project name does not exists")
        pass
Esempio n. 20
0
    def publishRegexMatchedTags(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        # Push all the public release tags to Github
        pOpenCommandList = ["git", "tag"]
        status = utils().popenTask(pOpenCommandList)
        output = status[0]
        output = output.split('\n')
        tagList = utils().removeSpaceAndSpecialCharFromList(output)

        if(args.deploy_bitbucket_tag[0] == '*'):
            pattern = re.compile("."+ args.deploy_bitbucket_tag)
        else:
            pattern = re.compile(args.deploy_bitbucket_tag)
        
        if(args.debug_mode):
            print("[Debug] publishRegexMatchedTags->tag regex input " + str(pattern))

        for tag in tagList:
            if(pattern.match(tag) != None):
                pOpenCommandList = ["git", "ls-remote", "origin", "refs/tags/" + tag]
                status = utils().popenTask(pOpenCommandList)
                output = status[0]
                
                self.excludeFilesForTag(args, tag)

                if(not output):
                    pOpenCommandList = ["git", "push", "origin", tag]
                    status = utils().popenTask(pOpenCommandList)
                    output = status[0]
                    print("[*] pushing tag " + tag + " to remote Github repo")
                else:
                    print("[-] Tag: " + tag + " is already present in the remote Github repo")
            else:
                print("[*] Tag:" + tag + " does not match the specified regex.")
Esempio n. 21
0
    def updatePrivateRepo(self, args, githubAccessHook):
        """
        :param args: command line input arguments
        :param githubAccessHook: GitHub interface
        :type: Repository private access status
        """

        repoName = utils().repositoryNameGet(args.deploy_github_url)

        for repo in githubAccessHook.get_repos():
                # Check repo name
            if(repoName == repo.name):
                repo.edit(
                    private=True
                )
    def jsonSchemaOperation(self, args):
        # read json schema file and check syntax issue
        # read meta data file and compare with json schema file
        jsonSchema = ""
        metaData = ""

        try:
            jsonSchema = utils().readJsonFile(args.json_schema_file_path)
        except Exception as identifier:
            print("[!] Invalid Json schema json file format in : " +
                  args.json_schema_file_path)
            pass

        try:
            metaData = utils().readJsonFile(args.meta_data_file_path)
        except Exception as identifier:
            print("[!] Invalid meta data json file format in : " +
                  args.meta_data_file_path)
            pass

        self.schemaValidator(jsonSchema)
        self.validateMetaDataFileWithJsonSchema(jsonSchema, metaData)
        print("[*] No errors found. JSON validates against the schema")
        pass
Esempio n. 23
0
    def init_utils(self):
        """"
		Initialize a src.utils object.
		Args:
		Return:
		
                """
        conf_dir = self.conf_dir
        data_loader = self.data_loader
        exp_dir = self.exp_dir
        self.utils = utils.utils(conf_dir, exp_dir, data_loader.events)
        lst, csv = data_loader.get_test()
        self.utils.init_csv(csv)
        lst, csv = data_loader.get_vali()
        self.utils.init_csv(csv)
        self.utils.set_vali_csv(lst, csv)
Esempio n. 24
0
    def validateGitReleaseTag(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        INTERNAL_RELEASE_TAGS="internal"
        PUBLIC_RELEASE_TAGS="public"
        ALL_TAGS="all"

        exceptionString = ""

        if(args.deployment):
            if(args.deploy_bitbucket_tag):
                pattern = re.compile("^(.*?)\.(.*?)\..*$")
                if(not utils().checkSemanticVersioningRegex(args.deploy_bitbucket_tag) and (not args.deploy_bitbucket_tag == INTERNAL_RELEASE_TAGS)
                and (not args.deploy_bitbucket_tag == PUBLIC_RELEASE_TAGS) and (not args.deploy_bitbucket_tag == ALL_TAGS) and (None == pattern.match(args.deploy_bitbucket_tag))):
                    exceptionString += ('[!] Invalid deploy_bitbucket_tag version format. usage: \"-dtag=<release-tag-number>\" or \"-dtag=internal\" or \"-dtag=public\" or \"-dtag=all\" or \"-dtag=1.*.* (regex)\"')

        if(exceptionString):
            raise Exception (exceptionString)
Esempio n. 25
0
    def performRepoOperations(self, args, githubAccess):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: Boolean
        """

        print("[*] Starting repository process at " +
              utils().currentDataAndTimeGet())

        if (args.debug_mode):
            print("[Debug] performDeployOperations")

        if (args.repo_update):
            self.updateRepo(args, githubAccess)
        else:
            self.createRepo(args, githubAccess)

        if (args.repo_topics):
            self.updateRepoTopics(args, githubAccess)

        return True
Esempio n. 26
0
    def validateArgsFolderPath(self, args):
        """
        :param args: command line input arguments
        :type: Exception
        """

        exceptionString = ""
        
        if(args.deployment):
            if(args.deploy_bitbucket_repo_folder and not args.deploy_bitbucket_url):
                if not path.exists(args.deploy_bitbucket_repo_folder):
                    exceptionString += ('[!] Invalid deploy_bitbucket_repo_folder path: ' + str(args.deploy_bitbucket_repo_folder))
                else:
                    # Validate deploy bitbucket folder has git init folder
                    cwd = os.getcwd()
                    os.chdir(args.deploy_bitbucket_repo_folder)
                    pOpenCommandList = ["git", "rev-parse", "--git-dir"]
                    status = utils().popenTask(pOpenCommandList)
                    os.chdir(cwd)
                    if(status[0].find('.git') < 0):
                        exceptionString += ('[!] deploy_bitbucket_repo_folder -> .git folder is missing: ' + str(args.deploy_bitbucket_repo_folder))

        if(args.release_operation):
            if(args.release_note_path):
                args.release_note_path = os.path.join(deploy().workSpaceFolder, args.release_note_path)

                if not path.exists(args.release_note_path):
                    exceptionString += ('[!] Invalid release note file path: ' + args.release_note_path)
        
        if(args.validate_deploy_operation):
            if(args.meta_data_file_path or args.json_schema_file_path):
                if not path.exists(args.meta_data_file_path):
                    exceptionString += ('[!] Invalid meta data json file path: ' + args.meta_data_file_path)
                if not path.exists(args.json_schema_file_path):
                    exceptionString += ('[!] Invalid json schema file path: ' + args.json_schema_file_path)

        if(exceptionString):
            raise Exception (exceptionString)
Esempio n. 27
0
    def convertStringToBoolean(self, args):
        """
        :param args: command line input arguments
        :type: None
        """

        if(args.repo_has_issues):
            args.repo_has_issues = utils().boolenStringToBoolean(args.repo_has_issues)
        else:
            args.repo_has_issues = True

        if(args.repo_has_projects):
            args.repo_has_projects = utils().boolenStringToBoolean(args.repo_has_projects)
        else:
            args.repo_has_projects = True

        if(args.repo_private):
            args.repo_private = utils().boolenStringToBoolean(args.repo_private)
        else:
            args.repo_private = True

        args.debug_mode = utils().boolenStringToBoolean(args.debug_mode)
        args.repo_operation = utils().boolenStringToBoolean(args.repo_operation)
        args.release_operation = utils().boolenStringToBoolean(args.release_operation)
        args.edit_release = utils().boolenStringToBoolean(args.edit_release)
        args.delete_release = utils().boolenStringToBoolean(args.delete_release)
        args.deployment = utils().boolenStringToBoolean(args.deployment)
        args.repo_update = utils().boolenStringToBoolean(args.repo_update)
        args.bitbucket_tag_operation = utils().boolenStringToBoolean(args.bitbucket_tag_operation)
        args.deploy_mandatory_files_check_disable = utils().boolenStringToBoolean(args.deploy_mandatory_files_check_disable)
        args.disbale_release_error_check = utils().boolenStringToBoolean(args.disbale_release_error_check)
        args.deploy_ignore_default_all_tags_push = utils().boolenStringToBoolean(args.deploy_ignore_default_all_tags_push)
Esempio n. 28
0
    def _updateConfigFile(self):
        ''' save all update data '''

        # collect project setting data -----------
        projectData = self._collectProjectData()

        #check active state
        active_count = 0
        project_code_list = []

        for project in projectData.keys():
            project_name = projectData[project]['project_name']
            project_code = projectData[project]['project_code']
            project_path = projectData[project]['project_path']
            project_active = projectData[project]['active']

            # check blank field
            if project_name == "" or project_code == "" or project_path == "":
                logger.info("Please complete all project infomation : %s" %
                            project_name)
                return False

            # if blank all field, ignore item
            elif project_name == "" and project_code == "" and project_path == "":
                del projectData[project]
                continue

            # check duplicate project code
            if project_code in project_code_list:
                logger.info("Do not duplicate project code : %s" %
                            project_code)
                return False

            if project_active == True:
                active_count += 1

            project_code_list.append(project_code)

        if active_count > 1:
            logger.info("Only one project can active, Please check !!")
            return False
        elif active_count < 1:
            logger.info("Please select active project !!")
            return False

        # collect account setting data -----------
        accountData = self._collectAccountData()

        is_success = projectData and accountData
        is_confirm = confirmDialog(
            parent=self.ui,
            title="Update Config !!",
            message='Do you want to update config file?')

        data = {"setting": {"projects": projectData}, "username": accountData}

        if is_success and is_confirm:

            # skip when data not modified.
            if data != self.database:
                logger.info(json.dumps(data, indent=2))
                json.dump(data, open(self.databaseFilePath, 'w'), indent=2)

                #Create project folder
                for prj in data.get("setting")["projects"].keys():
                    project_path = data.get(
                        "setting")["projects"][prj]["project_path"]

                    # If directory not exists.
                    try:
                        dirList = os.listdir(project_path)
                    except WindowsError:
                        # Pass
                        continue

                    zipPath = "%s/%s/%s" % (modulepath, "data",
                                            "projectSetup_template.zip")
                    dest = project_path
                    if dirList == [] or 'production' not in dirList:
                        utils.utils().unzip(zipPath, dest)
                        logger.info("Create project Folder : " + str(dest))

                logger.info("Update success.")

            self.close()
Esempio n. 29
0
 def performBitbucketOperations(self, args):
     print("[*] Starting Bitbucket tag creation process at " +
           utils().currentDataAndTimeGet())
     gitAccess = self.connectBitBucket(args)
     self.create_tag(args, gitAccess)
Esempio n. 30
0
    def performReleaseOperations(self, args, githubAccess):
        """
        :param args: command line input arguments
        :param githubAccess: GitHub interface
        :type: Boolean
        """

        if (args.debug_mode):
            print("[Debug] performDeployOperations")

        findTagStatus = False
        tagVersions = []
        findRepoStatus = False
        repoList = []
        organizationMatch = False

        # --release_operation
        # --release_note_path
        # --tag_version
        # --tag_title
        # --upload_assets
        # --edit_release
        # --delete_release
        #
        # --github_personal_access_token
        # --repo_name
        # --debug_mode

        print("[*] Starting release process at " +
              utils().currentDataAndTimeGet())

        deploymentValidator().checkRepoIsBelongsToOrganization(
            args, githubAccess)

        if (not args.disbale_release_error_check):
            try:
                args.github_release_tag = args.tag_title
                deploymentValidator().isPresentGitHubReleaseTag(
                    args, githubAccess)
                pass
            except Exception as identifier:
                raise Exception(identifier)

        if (args.release_note_path):
            print("[*] Changelog file path: \"" + args.release_note_path +
                  "\"")

        try:
            for repo in githubAccess.get_user().get_repos():
                repoList.append(repo.full_name)
                # Check repo name

                if args.repo_organization:
                    if repo.full_name.find(args.repo_organization) > -1:
                        organizationMatch = True
                    else:
                        organizationMatch = False
                else:
                    organizationMatch = True

                if (args.repo_name == repo.name and organizationMatch):
                    print("[*] Repository fullname: " + repo.full_name)

                    findRepoStatus = True
                    if (args.delete_release or args.edit_release):
                        for releaseInfo in repo.get_releases():
                            tagVersions.append(releaseInfo.title)
                            # Check tag version
                            if (releaseInfo.title == args.tag_title):
                                findTagStatus = True
                                if (args.delete_release):
                                    # delete a release
                                    return self.deleteRelease(releaseInfo)
                                elif (args.edit_release):
                                    # edit a release
                                    return self.editRelease(
                                        args, repo, releaseInfo)
                    else:
                        return self.createRelease(args, repo)
            pass
        except Exception as e:
            if (args.debug_mode):
                print("[Debug] Exception: " + str(e))

            utils().githubExceptionWarningMessage(str(e))
            utils().githubExceptionErrorMessage(str(e))
            status = utils().errorMsgPrintForhttpStatusCode(args, str(e))
            if (status):
                raise Exception("")

        if (not findRepoStatus):
            if (repoList):
                print("[*] We found your repositories in github: " +
                      str(repoList))

            raise Exception("[!] Unable to find github repository name: " +
                            args.repo_name)

        if (findRepoStatus and not findTagStatus
                and (args.delete_release or args.edit_release)):
            if (tagVersions):
                print("[*] We found your tag titles in github repository: " +
                      str(tagVersions))

            raise Exception(
                "[!] Unable to find github repository tag title: " +
                args.tag_title)

        return True