default='corereview')
NOMERGE_KEY = 'NOMERGE'
ORIG_AUTHOR = 'orig_author'
ORIG_MESSAGE = 'orig_message'
TMPL_COMMIT_LOG_MSG = '%s/' + 'svn.commit.log.message.rev.%s.txt'  # (tmpdir,rev)

LOG_FILE_PATH = TMPDIR + '/' + get_config(
    CONFIGREADER, 'general', 'log-file', default='automerger.log')
VERSION_PREFIX = get_config(CONFIGREADER, 'general', 'version-prefix')
VERSION_PREFIX_FILTER = get_config(CONFIGREADER, 'general',
                                   'version-prefix-filter')
VERSIONS_REPOSITORY = get_config(CONFIGREADER, 'general',
                                 'versions-repository')

LOGGER = initlogger(APP_KEY, LOG_FILE_PATH, SVN_PASSWORD)
M_SHU = ShellUtils(LOGGER)
MERGE_SERVER_URL = 'http://' + get_config(
    CONFIGREADER, 'general', 'host', default='localhost') + ':' + get_config(
        CONFIGREADER, 'general', 'port', default='8080') + '/?%s'

FILES_TO_IGNORE_STR = get_config(CONFIGREADER, 'general', 'files-to-ignore')
FILES_TO_IGNORE = FILES_TO_IGNORE_STR.split(
    ',') if FILES_TO_IGNORE_STR else None
AUTHORS_TO_IGNORE_STR = get_config(CONFIGREADER, 'general',
                                   'authors-to-ignore')
AUTHORS_TO_IGNORE = AUTHORS_TO_IGNORE_STR.split(
    ',') if AUTHORS_TO_IGNORE_STR else None

ENUM_CODE_FREEZE = 0
ENUM_EXCLUDED = 1
ENUM_MERGE = 2
Example #2
0
 def __init__(self, svn_cmd_params):
     self.logger = svn_cmd_params.logger
     self.tmpdir = svn_cmd_params.tmpdir
     self.username = svn_cmd_params.username
     self.password = svn_cmd_params.password
     self.shellutils = ShellUtils(svn_cmd_params.logger)
Example #3
0
 def __init__(self, svn_cmd_params):
     self.logger = svn_cmd_params.logger
     self.tmpdir = svn_cmd_params.tmpdir
     self.username = svn_cmd_params.username
     self.password = svn_cmd_params.password
     self.shellutils = ShellUtils(svn_cmd_params.logger)
Example #4
0
class SVNUtils:
    """
    General svn utilities, used heavily as auto merger works with svn.
    """
    def __init__(self, svn_cmd_params):
        self.logger = svn_cmd_params.logger
        self.tmpdir = svn_cmd_params.tmpdir
        self.username = svn_cmd_params.username
        self.password = svn_cmd_params.password
        self.shellutils = ShellUtils(svn_cmd_params.logger)

    def log(self, url, startdate, enddate, isxml=False, stoponcopy=False):
        """
        Run svn log commmand.
        """
        logcommand = LOG_URL_TMP % (url, '{' + startdate + '}', '{' + enddate + '}', self.username, self.password, 
                                    ' --xml' if isxml else '', ' --stop-on-copy' if stoponcopy else '')
        logging.info(logcommand)
        return M_SHU.runshellcmd(logcommand)

    def get_log_message(self, url, rev):
        """
        Get commit log message by url and revision
        Arguments:
            url: Url to get commit log message for.
            rev: Revision to get the commit log message for the url above.
        Returns: 
            The message which was committed on revision rev on url specified.
        """
        mergeconf.LOGGER.debug("Commit log message for url [%s] with rev [%s]" % (url, rev))
        log_cmd = (LOG_URL_TMP % (url, rev, rev, self.username, self.password))
        return M_SHU.runshellcmd(log_cmd)

        
    def commit(self, fileordir_to_commit, message, rev):
        """
        Commit files into svn repository with message specified.
        Arguments:
            fileordir_to_commit: The working directory (or file) to commit to svn - path to them.
            message: The message to commit with (-m)
            rev: We are going to write an internal temporary file with the message 
                we will use this rev for its naming convention.
        Returns: The message response from svn server.
        """
        mergeconf.LOGGER.debug("Committing file/dir %s with message %s" % 
                               (fileordir_to_commit, message))
        message_file_name = TMPL_COMMIT_LOG_MSG % (self.tmpdir, rev)
        message_file_name_org = message_file_name + '.org'
        mergeconf.LOGGER.debug("Creating message file: %s" % 
                               (message_file_name_org))
        message_file = open(message_file_name_org, 'w')
        try:
            message_file.write(message)
            message_file.close()
            svn_commit_merged_cmd = (COMMIT_TMPL % 
                                     (fileordir_to_commit, message_file_name, 
                                      self.username, self.password))
            initial_msg_file = open(message_file_name_org, 'rb')
            msg_file = open(message_file_name, 'wb')
            for line in initial_msg_file:
                line = line.replace('\r', '')
                line = line.replace('\n', '')
                if line != '':
                    msg_file.write(line + '\n')
            initial_msg_file.close()
            msg_file.close()
            result = self.shellutils.runshellcmd(svn_commit_merged_cmd)
            mergeconf.LOGGER.debug(svn_commit_merged_cmd)
        finally:
            os.remove(message_file_name)
        mergeconf.LOGGER.debug('returning result: ' + result)
        return result


    def update_local_workbranch(self, branch_dir):
        """Does everything it can to verify the current 
            working branch which is being used for merges is updated 
            and synced with svn so we can perform the merge 
            on this local branch.
            
            Args:
                merge_to_branch: The branch name we want to merge a commit into.
                user: Auto merging will use this svn username to perform the merge.
                pass: Auto merging will use this svn password to perform the merge.
            Returns:
                Nothing, local working branch will be updated in order to perform the auto merge.
        """
        M_SHU.runshellcmd(CLEANUP_TMPL % (TMPDIR, branch_dir, self.username, self.password))
        M_SHU.runshellcmd(REVERT_TMPL % (TMPDIR, branch_dir, self.username, self.password))
        M_SHU.runshellcmd(UPDATE_TMPL % (TMPDIR, branch_dir, self.username, self.password))

    def checkout(self, url, tolocation):
        """Given a branch url check it out to the local disk.
            
            Args:
                url: The branch to check out.
                tolocation: Location on disk to check out to.
                svn_username: Auto merging will use this svn username to perform the checkout.
                svn_password: Auto merging will use this svn password to perform the checkout.
            Returns:
                Nothing, the branch specified in url will be checked out to local disk.
        """
        checkout_cmd = CO_TMPL % (url, TMPDIR, tolocation + '/', self.username, self.password)
        M_SHU.runshellcmd(checkout_cmd) # branch to merge to does not exist in disk, check it out from svn.

    def merge_to_branch(self, revstart, revend=None, merge_from_url=None,
                        merge_to_branch=None):
        """Given a branch url merge it into a local branch.
            
            Args:
                merge_from_url: The url to merge from.
                merge_to_branch: The branch to merge to.
                revstart: Rev to merge from.
                revend: If not specified only revstart is merged otherwise merging a range of revisions.
                svn_username: Auto merging will use this svn username to perform the merge.
                svn_password: Auto merging will use this svn password to perform the merge.
            Returns:
                Nothing, The branch will be synced on disk.
        """
        mergeconf.LOGGER.debug('\nMerging...')
        prev_rev = int(revstart) - 1 # In svn when merging single revision then merging from merge_rev - 1 to merge_rev
        prev_rev_as_str = str(prev_rev)
        if revend is None:
            rev_as_str = str(revstart)
        else:
            rev_as_str = str(revend)
        svn_merge_cmd = MERGE_TMPL % (prev_rev_as_str, rev_as_str, merge_from_url, TMPDIR, get_branch_dir
                (merge_to_branch), self.username, self.password)
        mergeconf.LOGGER.debug('merge cmd: : ' + svn_merge_cmd)
        merge_result = M_SHU.runshellcmd(svn_merge_cmd)
        mergeconf.LOGGER.debug('merge result:' + merge_result)
        mergeconf.LOGGER.debug('merge cmd: : ' + svn_merge_cmd)
        return rev_as_str
Example #5
0
class SVNUtils:
    """
    General svn utilities, used heavily as auto merger works with svn.
    """
    def __init__(self, svn_cmd_params):
        self.logger = svn_cmd_params.logger
        self.tmpdir = svn_cmd_params.tmpdir
        self.username = svn_cmd_params.username
        self.password = svn_cmd_params.password
        self.shellutils = ShellUtils(svn_cmd_params.logger)

    def log(self, url, startdate, enddate, isxml=False, stoponcopy=False):
        """
        Run svn log commmand.
        """
        logcommand = LOG_URL_TMP % (url, '{' + startdate + '}',
                                    '{' + enddate + '}', self.username,
                                    self.password, ' --xml' if isxml else '',
                                    ' --stop-on-copy' if stoponcopy else '')
        logging.info(logcommand)
        return M_SHU.runshellcmd(logcommand)

    def get_log_message(self, url, rev):
        """
        Get commit log message by url and revision
        Arguments:
            url: Url to get commit log message for.
            rev: Revision to get the commit log message for the url above.
        Returns: 
            The message which was committed on revision rev on url specified.
        """
        mergeconf.LOGGER.debug(
            "Commit log message for url [%s] with rev [%s]" % (url, rev))
        log_cmd = (LOG_URL_TMP % (url, rev, rev, self.username, self.password))
        return M_SHU.runshellcmd(log_cmd)

    def commit(self, fileordir_to_commit, message, rev):
        """
        Commit files into svn repository with message specified.
        Arguments:
            fileordir_to_commit: The working directory (or file) to commit to svn - path to them.
            message: The message to commit with (-m)
            rev: We are going to write an internal temporary file with the message 
                we will use this rev for its naming convention.
        Returns: The message response from svn server.
        """
        mergeconf.LOGGER.debug("Committing file/dir %s with message %s" %
                               (fileordir_to_commit, message))
        message_file_name = TMPL_COMMIT_LOG_MSG % (self.tmpdir, rev)
        message_file_name_org = message_file_name + '.org'
        mergeconf.LOGGER.debug("Creating message file: %s" %
                               (message_file_name_org))
        message_file = open(message_file_name_org, 'w')
        try:
            message_file.write(message)
            message_file.close()
            svn_commit_merged_cmd = (COMMIT_TMPL %
                                     (fileordir_to_commit, message_file_name,
                                      self.username, self.password))
            initial_msg_file = open(message_file_name_org, 'rb')
            msg_file = open(message_file_name, 'wb')
            for line in initial_msg_file:
                line = line.replace('\r', '')
                line = line.replace('\n', '')
                if line != '':
                    msg_file.write(line + '\n')
            initial_msg_file.close()
            msg_file.close()
            result = self.shellutils.runshellcmd(svn_commit_merged_cmd)
            mergeconf.LOGGER.debug(svn_commit_merged_cmd)
        finally:
            os.remove(message_file_name)
        mergeconf.LOGGER.debug('returning result: ' + result)
        return result

    def update_local_workbranch(self, branch_dir):
        """Does everything it can to verify the current 
            working branch which is being used for merges is updated 
            and synced with svn so we can perform the merge 
            on this local branch.
            
            Args:
                merge_to_branch: The branch name we want to merge a commit into.
                user: Auto merging will use this svn username to perform the merge.
                pass: Auto merging will use this svn password to perform the merge.
            Returns:
                Nothing, local working branch will be updated in order to perform the auto merge.
        """
        M_SHU.runshellcmd(CLEANUP_TMPL %
                          (TMPDIR, branch_dir, self.username, self.password))
        M_SHU.runshellcmd(REVERT_TMPL %
                          (TMPDIR, branch_dir, self.username, self.password))
        M_SHU.runshellcmd(UPDATE_TMPL %
                          (TMPDIR, branch_dir, self.username, self.password))

    def checkout(self, url, tolocation):
        """Given a branch url check it out to the local disk.
            
            Args:
                url: The branch to check out.
                tolocation: Location on disk to check out to.
                svn_username: Auto merging will use this svn username to perform the checkout.
                svn_password: Auto merging will use this svn password to perform the checkout.
            Returns:
                Nothing, the branch specified in url will be checked out to local disk.
        """
        checkout_cmd = CO_TMPL % (url, TMPDIR, tolocation + '/', self.username,
                                  self.password)
        M_SHU.runshellcmd(
            checkout_cmd
        )  # branch to merge to does not exist in disk, check it out from svn.

    def merge_to_branch(self,
                        revstart,
                        revend=None,
                        merge_from_url=None,
                        merge_to_branch=None):
        """Given a branch url merge it into a local branch.
            
            Args:
                merge_from_url: The url to merge from.
                merge_to_branch: The branch to merge to.
                revstart: Rev to merge from.
                revend: If not specified only revstart is merged otherwise merging a range of revisions.
                svn_username: Auto merging will use this svn username to perform the merge.
                svn_password: Auto merging will use this svn password to perform the merge.
            Returns:
                Nothing, The branch will be synced on disk.
        """
        mergeconf.LOGGER.debug('\nMerging...')
        prev_rev = int(
            revstart
        ) - 1  # In svn when merging single revision then merging from merge_rev - 1 to merge_rev
        prev_rev_as_str = str(prev_rev)
        if revend is None:
            rev_as_str = str(revstart)
        else:
            rev_as_str = str(revend)
        svn_merge_cmd = MERGE_TMPL % (
            prev_rev_as_str, rev_as_str, merge_from_url, TMPDIR,
            get_branch_dir(merge_to_branch), self.username, self.password)
        mergeconf.LOGGER.debug('merge cmd: : ' + svn_merge_cmd)
        merge_result = M_SHU.runshellcmd(svn_merge_cmd)
        mergeconf.LOGGER.debug('merge result:' + merge_result)
        mergeconf.LOGGER.debug('merge cmd: : ' + svn_merge_cmd)
        return rev_as_str