當前位置: 首頁>>代碼示例>>Python>>正文


Python Project.addListPrerequis方法代碼示例

本文整理匯總了Python中Project.Project.addListPrerequis方法的典型用法代碼示例。如果您正苦於以下問題:Python Project.addListPrerequis方法的具體用法?Python Project.addListPrerequis怎麽用?Python Project.addListPrerequis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Project.Project的用法示例。


在下文中一共展示了Project.addListPrerequis方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from Project import Project [as 別名]
# 或者: from Project.Project import addListPrerequis [as 別名]
class Parser:
    '''
    Class to parse our file, it will check our file
    '''
    def __init__(self):
        '''
        Constructor for the class
        '''
        self._project = Project()

    def error_message(self, msg='unknown error', code_error=84):
        '''
        Write an error message on stderr and exit the program with code 84
        :param msg: message we will display on our stderr
        :param code_error: code error we will use to exit
        '''
        sys.stderr.write(msg + '\n')
        sys.exit(code_error)

    def _parseLine(self, line):
        '''
        we will parse the line if we have a correct line and add into our project
        if any error -> print on stderr + exit with code 84
        :param line: line we will parse
        :return:
        '''
        tokens = line.split(';')
        if len(tokens) < 3:
            self.error_message('error: [%s]: you must specify at least 3 elements' % (line))
        elif int(tokens[2]) and int(tokens[2]) < 0:
            self.error_message('error: [%s]: time must be >= 0' % (line))
        self._project.addTask(tokens[0])
        self._project.addDesc(tokens[0], tokens[1])
        self._project.addTime(tokens[0], tokens[2])
        if len(tokens) > 3:
            self._project.addListPrerequis(tokens[0], tokens[3:])

    def parseFile(self, file):
        '''
        Try to open our file and call _parseLine to check each line
        if any error -> print on stderr + exit with code 84
        :param file: filepath like './bonus/test/test1'
        '''
        try:
            with open(file, 'r') as f:
                data = f.readlines()
                lines = [x.rstrip('\n').decode('latin-1') for x in data]
            for x in lines:
                self._parseLine(x)
        except IOError as e:
            self.error_message('error: [%s]: %s' % (file, e.strerror))
        except BaseException:
            self.error_message('error: [%s]: Unknown error' % file)

    def getProject(self):
        '''
        get tasks from our project generated from our file (from our scrip from our directory etc...)
        :return: tasks (dictionnary)
        '''
        return self._project
開發者ID:Ankirama,項目名稱:Epitech,代碼行數:62,代碼來源:Parser.py


注:本文中的Project.Project.addListPrerequis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。