Пример #1
0
def HandleDiffCommand(argv: list, argc: int) -> ErrorCode:
    result = ErrorCode.OK

    HELP_MESSAGE = \
    """
    Get difference between Git versions.

    Usage:
    version_manager.py version get diff [optional] <from> <to>

    Required:
    from    The Git version to compare from
    to      The Git versionn to compare to

    Optional:
    help    Print this message
    """

    argv = argv[1:]
    argc = len(argv)

    fromArg = argv[0]
    if (fromArg == 'help'):
        print(HELP_MESSAGE)
        return result

    if (argc < 2):
        Logger.Error(LOG_TAG, 'Missing arguments')
        return ErrorCode.TOO_FEW_ARGUMENTS
    toArg = argv[1]

    responseTemplate = \
    """
    Commit difference between {0} and {1}:
    {2}
    """

    difference = Version.GetCommitsBetweenIds(fromArg, toArg)
    difference = ''.join(
        list(
            map(
                lambda commit: """
=========================================
Author: {0}
Date: {1}
Title: {2}
Message: {3}
=========================================
""".format(commit.author.name, Date.ConvertDateToString(commit.date), commit.
           title, commit.message), difference)))
    print(responseTemplate.format(fromArg, toArg, difference))

    return result
Пример #2
0
    def Send(templateFilePath: str, commits: list) -> ErrorCode:
        """
      Send an HTML email of the given commits in the style
      of the given template file. Use the email
      settings (subject, to, from) from the config.json.

      Args:
         templateFilePath (str): The path to the email template file.
         commits (list): The list of commits to list in the email.
      
      Returns:
         An ErrorCode object telling what the outcome of calling the function was.
      """
        COMMIT_LIST_ITEM_FORMAT = \
  """
<li>
   {title}
   {author}
   {date}
   {message}
</li>
"""
        config = Config.GetConfig()
        email = EmailMessage()
        email['Subject'] = config.get('Email').get('Subject')
        email['To'] = config.get('Email').get('To')
        email['From'] = config.get('Email').get('From')

        version = ""
        author = ""
        if (len(commits)):
            author = commits[0].author
            version = commits[0].tag

        textTemplate = ""
        htmlPart = ""
        try:
            with open(templateFilePath, 'r') as templateFile:
                textTemplate = templateFile.read()
        except IOError as err:
            Logger.Error(LOG_TAG, err)
            return ErrorCode.FILE_ERROR

        if (len(textTemplate) == 0):
            Logger.Error(LOG_TAG, "Template file empty")
            return ErrorCode.FILE_ERROR

        htmlPart = textTemplate.format(
            title=config.get('Email').get('Subject'),
            version=version,
            author=author,
            changeLog='\n'.join(
                list(
                    map(lambda x: HTMLEmail.COMMIT_LIST_ITEM_FORMAT.format(
                        title=x.title,
                        author=x.author,
                        date=Date.ConvertDateToString(x.date),
                        message=x.message)))))
        email.set_content(htmlPart)
        email.add_alternative(htmlPart, subtype='html')

        smtp = smtplib.SMTP(config.get('Email').get('SMTP').get('Server'))
        smtp.send(email)
        smtp.quit()

        return ErrorCode.OK