예제 #1
0
파일: parse.py 프로젝트: tern-tools/tern
def find_git_info(line, dockerfile_path):
    '''Given a line of ADD command and the path of dockerfile,
    return the information(string format) on the git project name and sha
    if the dockerfile is included in a git repository.
    ADD command has a general format:
    ADD [--chown=<user>:<group>] <src> <dst>
    Currently we parse the <src>, but not use it.
    '''
    args = line.split(' ')
    src_path = ''
    # check if --chown exists
    if args[1].startswith('--chown'):
        # check if the line is valid
        if len(args) < 4:
            logger.error('Invalid ADD command line')
        src_path = args[2]
    else:
        # the line has no --chown option
        if len(args) < 3:
            logger.error('Invalid ADD command line')
        src_path = args[1]
    # log the parsed src_path
    logger.debug('Parsed src_path is %s', src_path)
    # get the git project info
    comment_line = common.check_git_src(dockerfile_path)
    # get the git project link
    url_list = common.get_git_url(dockerfile_path)
    if url_list:
        comment_url = ', '.join(url_list)
        comment_line += ', project url(s): ' + comment_url
    return comment_line
예제 #2
0
 def testGetGitURL(self):
     ''' we check the url to be the following form:
     github.com/<username>/tern'''
     url_list = common.get_git_url(self.test_dockerfile)
     check_num = len(url_list)
     pass_num = 0
     git_username_reg = r'([a-zA-Z\d_-]{0,38})'
     pattern = re.compile(r'github.com/' + git_username_reg + r'/tern')
     for url in url_list:
         if pattern.match(url):
             pass_num += 1
     self.assertEqual(pass_num, check_num)