def handle_merge_failed(revstart, revend, current_branch_name,
                        next_branch_name, message, author, rev_as_str,
                        commit_merge_result):
    mergeconf.LOGGER.debug('merge failed')
    try:
        mailutils.mail(
            mergeconf.get_dl(author, mergeconf.ENUM_MERGE),
            get_failed_mergecommit_subject(current_branch_name,
                                           next_branch_name, author,
                                           rev_as_str),
            get_failed_mergecommit_text(current_branch_name, next_branch_name,
                                        message, author, rev_as_str,
                                        commit_merge_result),
            mergeconf.MAIL_ENABLED)
    except:
        LOGGER.error(
            "Please check mail configuration, failed sending email...")
    audit_write(AUDIT_OP_MERGE, author, current_branch_name, next_branch_name,
                revstart, revend, NA, NA, AUDIT_RES_FAILED_CONFLICT)
    add_row(
        {
            mergeconf.TYPE_COL: SPREADSHEET_MERGE_FAILED,
            'who': SPREADSHEET_AUTHOR_PREFIX + author,
            'frombranch': current_branch_name,
            'tobranch': next_branch_name,
            'rfrom': revstart,
            'rend': revend,
            'rcommit': NA,
            'bugid': mergeconf.ISSUE_ID_DEFAULT_VALUE,
            'details': SPREADSHEET_CONFLICT_MSG
        }, mergeconf.SPREADSHEET_USERNAME, mergeconf.SPREADSHEET_PASSWORD,
        mergeconf.SPREADSHEET_KEY, mergeconf.SPREADSHEET_WORKSHEET_ID,
        mergeconf.APP_KEY)
def handle_success_merge(revstart, revend, current_branch_name,
                         next_branch_name, message, author, rev_as_str,
                         commit_message, commit_merge_result):
    audit_write(AUDIT_OP_MERGE, author, current_branch_name, next_branch_name,
                revstart, revend, NA, NA, CSV_STATUS_MERGE_SUCCESS)
    rcommit = get_commit_rev_by_resp(commit_merge_result)
    try:
        mailutils.mail(
            mergeconf.get_dl(author, mergeconf.ENUM_MERGE),
            get_merge_success_subject(current_branch_name, next_branch_name,
                                      author, rev_as_str),
            get_merge_success_text(current_branch_name, next_branch_name,
                                   message, author, rev_as_str,
                                   commit_merge_result),
            mergeconf.MAIL_ENABLED)
    except:
        LOGGER.error(
            "Please check mail configuration, failed sending email...")
    add_row(
        {
            mergeconf.TYPE_COL: SPREADSHEET_MERGE,
            'who': SPREADSHEET_AUTHOR_PREFIX + author,
            'frombranch': current_branch_name,
            'tobranch': next_branch_name,
            'rfrom': revstart,
            'rend': revend,
            'rcommit': rcommit,
            'bugid': mergeconf.ISSUE_ID_DEFAULT_VALUE,
            'details': commit_message
        }, mergeconf.SPREADSHEET_USERNAME, mergeconf.SPREADSHEET_PASSWORD,
        mergeconf.SPREADSHEET_KEY, mergeconf.SPREADSHEET_WORKSHEET_ID,
        mergeconf.APP_KEY)
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id,
            asource):
    if not mergeconf.SPREADSHEET_ENABLED:
        LOGGER.debug("Not writing to spreadsheet as its not enabled...")
        return
    mergeconf.LOGGER.debug("spreadsheet_key: [" + aspreadsheet_key +
                           "] worksheetid: [" + aworksheet_id + "] source: [" +
                           asource + "]")
    password = apassword
    spreadsheet_key = aspreadsheet_key
    # All spreadsheets have worksheets. worksheet #1 by default always has a value of 'od6'
    worksheet_id = 'od6'

    spr_client = gdata.spreadsheet.service.SpreadsheetsService()
    spr_client.email = username
    spr_client.password = password
    spr_client.source = asource
    spr_client.ProgrammaticLogin()

    # Prepare the dictionary to write
    rowdict['date'] = time.strftime('%m/%d/%Y')
    logging.info(rowdict)

    entry = spr_client.InsertRow(rowdict, spreadsheet_key, worksheet_id)
    if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
        logging.info("Insert row succeeded.")
    else:
        logging.info("Insert row failed.")
Пример #4
0
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id, asource):
    if not mergeconf.SPREADSHEET_ENABLED:
        LOGGER.debug("Not writing to spreadsheet as its not enabled...")
        return
    mergeconf.LOGGER.debug("spreadsheet_key: [" + aspreadsheet_key + "] worksheetid: [" + aworksheet_id + "] source: [" + asource + "]")
    password = apassword
    spreadsheet_key = aspreadsheet_key
    # All spreadsheets have worksheets. worksheet #1 by default always has a value of 'od6'
    worksheet_id = 'od6'
    
    spr_client = gdata.spreadsheet.service.SpreadsheetsService()
    spr_client.email = username
    spr_client.password = password
    spr_client.source = asource
    spr_client.ProgrammaticLogin()
    
    # Prepare the dictionary to write
    rowdict['date'] = time.strftime('%m/%d/%Y')
    logging.info(rowdict)
    
    entry = spr_client.InsertRow(rowdict, spreadsheet_key, worksheet_id)
    if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
        logging.info("Insert row succeeded.")
    else:
        logging.info("Insert row failed.")
Пример #5
0
def handle_merge_failed(revstart, revend, current_branch_name, next_branch_name, message, author, rev_as_str, commit_merge_result):
    mergeconf.LOGGER.debug('merge failed')
    try:
        mailutils.mail(mergeconf.get_dl(author, mergeconf.ENUM_MERGE), get_failed_mergecommit_subject(current_branch_name, next_branch_name, author, rev_as_str), get_failed_mergecommit_text(current_branch_name, next_branch_name, message, author, rev_as_str, commit_merge_result), mergeconf.MAIL_ENABLED)
    except:
        LOGGER.error("Please check mail configuration, failed sending email...")
    audit_write(AUDIT_OP_MERGE, author, current_branch_name, next_branch_name, revstart, revend, NA, NA, AUDIT_RES_FAILED_CONFLICT)
    add_row({mergeconf.TYPE_COL:SPREADSHEET_MERGE_FAILED, 'who':SPREADSHEET_AUTHOR_PREFIX + author, 'frombranch':current_branch_name, 'tobranch':next_branch_name, 'rfrom':revstart, 'rend':revend, 'rcommit':NA, 'bugid':mergeconf.ISSUE_ID_DEFAULT_VALUE, 'details':SPREADSHEET_CONFLICT_MSG}, mergeconf.SPREADSHEET_USERNAME, mergeconf.SPREADSHEET_PASSWORD, mergeconf.SPREADSHEET_KEY, mergeconf.SPREADSHEET_WORKSHEET_ID, mergeconf.APP_KEY)
Пример #6
0
def handle_success_merge(revstart, revend, current_branch_name, next_branch_name, message, author, rev_as_str, commit_message, commit_merge_result):
    audit_write(AUDIT_OP_MERGE, author, current_branch_name, next_branch_name, revstart, revend, NA, NA, CSV_STATUS_MERGE_SUCCESS)
    rcommit = get_commit_rev_by_resp(commit_merge_result)
    try:
        mailutils.mail(mergeconf.get_dl(author, mergeconf.ENUM_MERGE), get_merge_success_subject(current_branch_name, next_branch_name, author, rev_as_str), get_merge_success_text(current_branch_name, next_branch_name, message, author, rev_as_str, commit_merge_result), mergeconf.MAIL_ENABLED)
    except:
        LOGGER.error("Please check mail configuration, failed sending email...")
    add_row({mergeconf.TYPE_COL:SPREADSHEET_MERGE, 'who':SPREADSHEET_AUTHOR_PREFIX + author, 'frombranch':current_branch_name, 'tobranch':next_branch_name, 'rfrom':revstart, 'rend':revend, 'rcommit':rcommit, 'bugid':mergeconf.ISSUE_ID_DEFAULT_VALUE, 'details':commit_message}, mergeconf.SPREADSHEET_USERNAME, mergeconf.SPREADSHEET_PASSWORD, mergeconf.SPREADSHEET_KEY, mergeconf.SPREADSHEET_WORKSHEET_ID, mergeconf.APP_KEY)
Пример #7
0
def write_merge_produced(rev, branch, REPO, status):
    """
       Update audit file that a commit was performed.
       
       Args:
           rev: Revision that has been committed.
           branch: The branch on which this commit has been performed.
           REPO: The repository on which this commit has been performed.
           status: Whether managed to update the server about this commit or not.
       
       Returns:
         Result: Updates audit file with commit details (PRODUCTION of a merge unit).
    """
    LOGGER.debug('Writing merge produce:\n %s,%s,%s,%s,%s' %
                 (mergeconf.MERGE_PRODUCER_CSV, REPO, branch, rev, status))
    writer = csv.writer(open(mergeconf.MERGE_PRODUCER_CSV, 'ab', buffering=0))
    writer.writerows([(REPO, branch, rev, status)])
Пример #8
0
def write_merge_produced(rev, branch, REPO, status):
    """
       Update audit file that a commit was performed.
       
       Args:
           rev: Revision that has been committed.
           branch: The branch on which this commit has been performed.
           REPO: The repository on which this commit has been performed.
           status: Whether managed to update the server about this commit or not.
       
       Returns:
         Result: Updates audit file with commit details (PRODUCTION of a merge unit).
    """
    LOGGER.debug('Writing merge produce:\n %s,%s,%s,%s,%s' % (mergeconf.MERGE_PRODUCER_CSV, REPO, branch, rev, status))
    writer = csv.writer(open(mergeconf.MERGE_PRODUCER_CSV, 'ab', buffering=0))
    writer.writerows([
        (REPO,branch,rev,status)
    ])
Пример #9
0
def mail(recipients, subject, text, mailenabled=True):
    """Send an email to recipients with specified subject,text.

    Args:
      to: Array of recipients.
      subject: str subject of email to be sent.
      text: str The body text of the email.

    Returns:
      Nothing, just sends an email.
    """
    if not mailenabled:
        LOGGER.debug('Not sending mail, not enabled...')
    else:
        smtp_server = mergeconf.SMTP_HOST
        smtp_port = mergeconf.SMTP_PORT
        login = mergeconf.MAIL_USERNAME
        sender = mergeconf.MAIL_FROM_NAME
        password = mergeconf.MAIL_PASSWORD
        recipient = recipients
        subject = subject
        body = text

        body = "" + body + ""

        headers = [
            "From: " + sender, "Subject: " + subject,
            "To: " + ';'.join(recipient), "MIME-Version: 1.0",
            "Content-Type: text/plain"
        ]
        headers = "\r\n".join(headers)

        mergeconf.LOGGER.debug(headers + '\n' + body)

        session = smtplib.SMTP(smtp_server, smtp_port)

        session.ehlo()
        session.starttls()
        session.ehlo()

        session.login(login, password)
        session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
        session.quit()
Пример #10
0
def mail(recipients, subject, text, mailenabled=True):
    """Send an email to recipients with specified subject,text.

    Args:
      to: Array of recipients.
      subject: str subject of email to be sent.
      text: str The body text of the email.

    Returns:
      Nothing, just sends an email.
    """
    if not mailenabled:
        LOGGER.debug('Not sending mail, not enabled...')
    else:
        smtp_server = mergeconf.SMTP_HOST
        smtp_port = mergeconf.SMTP_PORT
        login = mergeconf.MAIL_USERNAME
        sender = mergeconf.MAIL_FROM_NAME
        password = mergeconf.MAIL_PASSWORD
        recipient = recipients
        subject = subject
        body = text
        
        body = "" + body + ""
        
        headers = ["From: " + sender,
                   "Subject: " + subject,
                   "To: " + ';'.join(recipient),
                   "MIME-Version: 1.0",
                   "Content-Type: text/plain"]
        headers = "\r\n".join(headers)
        
        mergeconf.LOGGER.debug(headers + '\n' + body)
    
        session = smtplib.SMTP(smtp_server, smtp_port)
        
        session.ehlo()
        session.starttls()
        session.ehlo()
        
        session.login(login, password)
        session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
        session.quit()
Пример #11
0
from Queue import Queue
import sys
from merger.logic.mergeserver import ConsumeFromQueue
from merger.conf.mergeconf import LOGGER
from merger.logic.postcommit import produce_merge
from merger.logic.mergeserver import start_webpy
import web

if __name__ == "__main__":
    for arg in sys.argv:
        LOGGER.debug('arg: ' + arg)
    if len(sys.argv) > 1 and sys.argv[1] == 'client':
        LOGGER.debug('auto merger client started...')
        produce_merge(sys.argv[2], sys.argv[3])
    else:  # its a server.
        start_webpy()
Пример #12
0
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id, asource):
    LOGGER.debug("Spreadsheet integration depracated...")
Пример #13
0
def produce_merge(repository, revision):
    """
       This method is called after a user commits to svn repository.
       We get here the repository and revision that was committed.
       We write here to the audit file PRODUCED which means a commit was made.
       Call the server to provide it with information about commit which
       was performed, and let the server continue handling this commit.
       
       Args:
        argv[1]: From post commit hook the repository on which commit was made. 
        argv[2]: From post commit hook the revision number assigned to commit performed.
       
       Returns:
         Result: updates csv audit with commit performed and calls server to treat that merge.
    """
    LOGGER.debug('auto merger %s ' % (mergeconf.VERSION))

    lookcmd = LOOK_CHANGED_TMPL % (revision, repository)
    LOGGER.debug('lookcmd: ' + lookcmd)
    result = mergeconf.M_SHU.runshellcmd(lookcmd)
    LOGGER.debug('result: ' + result)
    current_branch_name = svnutils.get_branch_by_look(result,
                                                      mergeconf.BRANCHES_MAP)

    # If the branch for which a commit just happended is not relevant to our branches.
    if not current_branch_name:
        LOGGER.debug(
            'produce_merge: current_branch_name:' + current_branch_name +
            ', Branch changed is not in list of branches to auto merge')
        write_merge_produced(revision, current_branch_name, repository,
                             mergeconf.CSV_STATUS_MERGE_IGNORED)
        return

    params = urllib.urlencode({
        mergeconf.KEY_REV_START: revision,
        mergeconf.KEY_REPO: repository
    })
    try:
        url = mergeconf.MERGE_SERVER_URL % params
        LOGGER.debug(url)
        f = urllib.urlopen(mergeconf.MERGE_SERVER_URL % params)
        write_merge_produced(revision, current_branch_name, repository,
                             mergeconf.CSV_STATUS_MERGE_PRODUCED)
        LOGGER.debug(f.read())
    except:
        write_merge_produced(revision, current_branch_name, repository,
                             mergeconf.CSV_STATUS_MERGE_FAILED)
        mergeconf.LOGGER.exception("exception occured")
Пример #14
0
import sys
from merger.conf.mergeconf import LOGGER
from merger.logic.postcommit import produce_merge
from merger.logic.mergeserver import start_webpy
from merger.utils.argutils import is_client


if __name__ == "__main__":
    for arg in sys.argv:
        LOGGER.debug('main arg: ' + arg)
    if is_client(sys.argv):
        LOGGER.debug('auto merger client started...')
        produce_merge(sys.argv[2], sys.argv[3])
    else: # its a server.
        start_webpy()
Пример #15
0

def write_merge_produced(rev, branch, REPO, status):
    """
       Update audit file that a commit was performed.
       
       Args:
           rev: Revision that has been committed.
           branch: The branch on which this commit has been performed.
           REPO: The repository on which this commit has been performed.
           status: Whether managed to update the server about this commit or not.
       
       Returns:
         Result: Updates audit file with commit details (PRODUCTION of a merge unit).
    """
    LOGGER.debug('Writing merge produce:\n %s,%s,%s,%s,%s' %
                 (mergeconf.MERGE_PRODUCER_CSV, REPO, branch, rev, status))
    writer = csv.writer(open(mergeconf.MERGE_PRODUCER_CSV, 'ab', buffering=0))
    writer.writerows([(REPO, branch, rev, status)])


if __name__ == "__main__":
    for arg in sys.argv:
        LOGGER.debug('arg: ' + arg)
    LOGGER.debug('repository: ' + sys.argv[1])
    LOGGER.debug('revision number: ' + sys.argv[2])
    repository = sys.argv[1]
    revision = sys.argv[2]
    LOGGER.debug("postcommit called...")
    produce_merge(repository, revision)
Пример #16
0
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id, asource):
    if not mergeconf.SPREADSHEET_ENABLED:
        LOGGER.debug("Not writing to spreadsheet as its not enabled...")
        return
Пример #17
0
def write_merge_produced(rev, branch, REPO, status):
    """
       Update audit file that a commit was performed.
       
       Args:
           rev: Revision that has been committed.
           branch: The branch on which this commit has been performed.
           REPO: The repository on which this commit has been performed.
           status: Whether managed to update the server about this commit or not.
       
       Returns:
         Result: Updates audit file with commit details (PRODUCTION of a merge unit).
    """
    LOGGER.debug('Writing merge produce:\n %s,%s,%s,%s,%s' % (mergeconf.MERGE_PRODUCER_CSV, REPO, branch, rev, status))
    writer = csv.writer(open(mergeconf.MERGE_PRODUCER_CSV, 'ab', buffering=0))
    writer.writerows([
        (REPO,branch,rev,status)
    ])
        

if __name__=="__main__":
    for arg in sys.argv:
        LOGGER.debug ('arg: ' + arg)
    LOGGER.debug('repository: ' + sys.argv[1])
    LOGGER.debug('revision number: ' + sys.argv[2])
    repository = sys.argv[1]
    revision = sys.argv[2]
    LOGGER.debug("postcommit called...")
    produce_merge(repository, revision)

Пример #18
0
def produce_merge(repository, revision):
    """
       This method is called after a user commits to svn repository.
       We get here the repository and revision that was committed.
       We write here to the audit file PRODUCED which means a commit was made.
       Call the server to provide it with information about commit which
       was performed, and let the server continue handling this commit.
       
       Args:
        argv[1]: From post commit hook the repository on which commit was made. 
        argv[2]: From post commit hook the revision number assigned to commit performed.
       
       Returns:
         Result: updates csv audit with commit performed and calls server to treat that merge.
    """
    LOGGER.debug('auto merger %s ' % (mergeconf.VERSION))

    lookcmd = LOOK_CHANGED_TMPL % (revision,repository)
    LOGGER.debug('lookcmd: ' + lookcmd)
    result = mergeconf.M_SHU.runshellcmd(lookcmd)
    LOGGER.debug('result: ' + result)
    current_branch_name = svnutils.get_branch_by_look(result, mergeconf.BRANCHES_MAP)

    # If the branch for which a commit just happended is not relevant to our branches.
    if not current_branch_name:
        LOGGER.debug('produce_merge: current_branch_name:' + current_branch_name + ', Branch changed is not in list of branches to auto merge')
        write_merge_produced(revision, current_branch_name, repository, mergeconf.CSV_STATUS_MERGE_IGNORED)
        return
    
    params = urllib.urlencode({mergeconf.KEY_REV_START: revision, mergeconf.KEY_REPO: repository})
    try:
        url = mergeconf.MERGE_SERVER_URL % params
        LOGGER.debug(url)
        f = urllib.urlopen(mergeconf.MERGE_SERVER_URL % params)
        write_merge_produced(revision, current_branch_name, repository, mergeconf.CSV_STATUS_MERGE_PRODUCED)
        LOGGER.debug(f.read())
    except:
        write_merge_produced(revision, current_branch_name, repository, mergeconf.CSV_STATUS_MERGE_FAILED)
        mergeconf.LOGGER.exception("exception occured")
Пример #19
0
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id,
            asource):
    LOGGER.debug("Spreadsheet integration depracated...")