Ejemplo n.º 1
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.")
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.")
Ejemplo n.º 3
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)])
Ejemplo n.º 4
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)
    ])
Ejemplo n.º 5
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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")
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id,
            asource):
    LOGGER.debug("Spreadsheet integration depracated...")
Ejemplo n.º 11
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")
Ejemplo n.º 12
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)

Ejemplo n.º 13
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
Ejemplo n.º 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()
Ejemplo n.º 15
0
def add_row(rowdict, username, apassword, aspreadsheet_key, aworksheet_id, asource):
    LOGGER.debug("Spreadsheet integration depracated...")