示例#1
0
    def function_by_signature(self, name, returns, parameters):
        method = DocsMethod(0)
        method.name = name
        method.parameters = parameters
        method.syntax = name + "("
        for p in self.get_parameter_names(parameters):
            method.syntax = method.syntax + p + ", "
        method.syntax = method.syntax.rstrip(', ')
        method.syntax = method.syntax + ")"
        method.returns = returns
        method.new = True
        found = False
        for function in self.function_list:
            if function.name == name:
                dst_parameters_types = self.get_parameter_types(function.parameters)
                src_parameters_types = self.get_parameter_types(parameters)

                if(len(src_parameters_types)==len(dst_parameters_types)):
                    a = -1
                    for i in range(len(src_parameters_types)):
                        if src_parameters_types[i] != dst_parameters_types[i]:
                            break
                        else:
                            a = i
                    if a == len(src_parameters_types)-1:
                        function.new = False
                        return function
                        found = True
                        #print 'found ' + function.name
                        break
        if not found:
            #print 'not found ' + method.name
            #clazzmethod = method
            self.function_list.append(method)   
        return method
def parse_function(element):
    if re.match('.*operator\s*\[\s*\]',element) is None: 
        clean_element = remove_links(element)
    else:
        clean_element = element
    clean_element = html_encode_templates(clean_element)
    #print re.match('operator\b*\[\b*\]\b*\(.*\)',element) is None
    #print clean_element
    m = DocsMethod(0)
    function_name = "" 
    function_return = ""
    function = clean_element.split('(')[0].lstrip(' ').rstrip(' ').split(' ')
    print str(function) + ": " + str(len(function)) + ": " + function[len(function)-1]
    
    #print function
    if len(function)>1:
        if element.find("operator")!=-1 and len(function)>2:
            function_name = function[len(function)-2] + function[len(function)-1]
        else:
            function_name = function[len(function)-1]
            print function_name
        for r in function[:len(function)-1]:
            if r == 'static':
                m.static = True
                continue
            if r == 'operator':
                continue
            if r == 'virtual':
                continue

            function_return = function_return + " " + r
    else:
        function_name = function[0]
    #print clean_element
    
    if clean_element.rfind('const') > clean_element.rfind(')'):
        clean_element = clean_element[:clean_element.rfind('const')]
        m.constant = True
        
    function_parameters = clean_element.split('(')[1].strip('\n').strip(' ').strip(')').strip(' ')
        
    m.name = function_name
    m.returns = function_return
    m.parameters = function_parameters
    m.syntax = function_name + "("
    for p in get_parameter_names(function_parameters):
        m.syntax = m.syntax + p + ", "
    m.syntax = m.syntax.rstrip(', ')
    m.syntax = m.syntax + ")"
    return m
示例#3
0
    def function_by_signature(self, name, returns, parameters):
        method = DocsMethod(0)
        method.name = name
        method.parameters = parameters
        method.syntax = name + "("
        for p in self.get_parameter_names(parameters):
            method.syntax = method.syntax + p + ", "
        method.syntax = method.syntax.rstrip(', ')
        method.syntax = method.syntax + ")"
        method.returns = returns
        method.new = True
        found = False
        for function in self.function_list:
            if function.name == name:
                dst_parameters_types = self.get_parameter_types(
                    function.parameters)
                src_parameters_types = self.get_parameter_types(parameters)

                if (len(src_parameters_types) == len(dst_parameters_types)):
                    a = -1
                    for i in range(len(src_parameters_types)):
                        if src_parameters_types[i] != dst_parameters_types[i]:
                            break
                        else:
                            a = i
                    if a == len(src_parameters_types) - 1:
                        function.new = False
                        return function
                        found = True
                        #print 'found ' + function.name
                        break
        if not found:
            #print 'not found ' + method.name
            #clazzmethod = method
            self.function_list.append(method)
        return method
示例#4
0
def getclass(clazz):
    method = DocsMethod(0)
    var = DocsVar(0)
    docs_clazz = DocsClass(0)
    var.clazz  = clazz
    docs_clazz.name = clazz
    docs_clazz.new = True
    for root, dirs, files in os.walk(os.path.join(docs_root)):
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1]=='.markdown' and file_split[0] == clazz: 
                f = open(os.path.join(root,name),'r')
                state = 'begin'
                for line in f:
                    if state == 'begin' and line.find('#class') == 0 and line.find(clazz)!=-1:
                        state = 'class'
                        docs_clazz.module = os.path.basename(root)
                        docs_clazz.new = False
                        
                    elif state == 'class' and line.rstrip('\n').rstrip(' ') == '##Methods':
                        state = 'methods'
                        
                    elif state == 'methods' and line.find('###') == 0:
                        #print "##########method: " + line
                        state = 'method'
                        
                    elif state == 'method' and line.find('_')==0 and line.find('_description')==-1:
                        #print "##########field: " + line
                        addfield(method,line)
                        
                    elif state == 'method' and line.find('_description')==0:
                        state = 'description'
                        
                    elif state == 'description' and line.find('##')!=0:
                        method.description = method.description + line
                        
                    elif state == 'description' and line.find('###') == 0:
                        state = 'method'
                        docs_clazz.function_list.append(method)
                        method = DocsMethod(0)
                        method.clazz  = docs_clazz.name
                        
                    elif state == 'description' and line.rstrip('\n').rstrip(' ') == '##Variables':
                        docs_clazz.function_list.append(method)
                        state = 'vars'
                        
                    elif state == 'vars' and line.find('###') == 0:
                        #print line
                        state = 'var'
                        
                    elif state == 'var' and line.find('_')==0 and line.find('_description')==-1:
                        addfield(var,line)
                        
                    elif state == 'var' and line.find('_description') == 0:
                        state = 'vardescription'
                        
                    elif state == 'vardescription' and line.find('##')!=0:
                        var.description = var.description + line
                        
                    elif state == 'vardescription' and line.find('###') == 0:
                        #print line
                        state = 'var'
                        docs_clazz.var_list.append(var)
                        var = DocsVar(0)
                        var.clazz  = docs_clazz.name
                        
                    elif state == 'class' and line.find('##Description')==-1:
                        docs_clazz.reference  = docs_clazz.reference + line
                        
                if state == 'vardescription':
                    docs_clazz.var_list.append(var)
                f.close()
                return docs_clazz   


    return docs_clazz
示例#5
0
def getclass(clazz):
    method = DocsMethod(0)
    var = DocsVar(0)
    docs_clazz = DocsClass(0)
    var.clazz = clazz
    docs_clazz.name = clazz
    docs_clazz.new = True
    for root, dirs, files in os.walk(os.path.join(docs_root)):
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1] == '.markdown' and file_split[0] == clazz:
                f = open(os.path.join(root, name), 'r')
                state = 'begin'
                for line in f:
                    if state == 'begin' and line.find(
                            '#class') == 0 and line.find(clazz) != -1:
                        state = 'class'
                        docs_clazz.module = os.path.basename(root)
                        docs_clazz.new = False

                    elif state == 'class' and line.rstrip('\n').rstrip(
                            ' ') == '##Methods':
                        state = 'methods'

                    elif state == 'methods' and line.find('###') == 0:
                        #print "##########method: " + line
                        state = 'method'

                    elif state == 'method' and line.find(
                            '_') == 0 and line.find('_description') == -1:
                        #print "##########field: " + line
                        addfield(method, line)

                    elif state == 'method' and line.find('_description') == 0:
                        state = 'description'

                    elif state == 'description' and line.find('##') != 0:
                        method.description = method.description + line

                    elif state == 'description' and line.find('###') == 0:
                        state = 'method'
                        docs_clazz.function_list.append(method)
                        method = DocsMethod(0)
                        method.clazz = docs_clazz.name

                    elif state == 'description' and line.rstrip('\n').rstrip(
                            ' ') == '##Variables':
                        docs_clazz.function_list.append(method)
                        state = 'vars'

                    elif state == 'vars' and line.find('###') == 0:
                        #print line
                        state = 'var'

                    elif state == 'var' and line.find('_') == 0 and line.find(
                            '_description') == -1:
                        addfield(var, line)

                    elif state == 'var' and line.find('_description') == 0:
                        state = 'vardescription'

                    elif state == 'vardescription' and line.find('##') != 0:
                        var.description = var.description + line

                    elif state == 'vardescription' and line.find('###') == 0:
                        #print line
                        state = 'var'
                        docs_clazz.var_list.append(var)
                        var = DocsVar(0)
                        var.clazz = docs_clazz.name

                    elif state == 'class' and line.find('##Description') == -1:
                        docs_clazz.reference = docs_clazz.reference + line

                if state == 'vardescription':
                    docs_clazz.var_list.append(var)
                f.close()
                return docs_clazz

    return docs_clazz
def ofReferenceConvert():
    method = DocsMethod(0)  #from ofReference
    var = DocsVar(0)
    clazzmethod = DocsMethod(0)  #from markdown

    for root, dirs, files in os.walk(os.path.join(ofReference_path)):
        for name in files:
            file_split = os.path.splitext(name)
            if file_split[1]==".jpeg" or file_split[1]==".jpg" or file_split[1]==".gif" or file_split[1]==".png":
                try:
                    os.mkdir(os.path.join(docs_root,os.path.basename(root)))
                except:
                    pass
                shutil.copyfile(os.path.join(root,name), os.path.join(docs_root,os.path.basename(root),name))
            if file_split[1]=='.markdown': 
                print '###################get_class ' + file_split[0]
                clazz = getclass(file_split[0])
                clazztosave = getclass(file_split[0])
                if clazztosave.new:
                    clazztosave.module = root
                    print os.path.basename(root)

                f = open(os.path.join(root,name),'r')
                state = 'clazz'
                for line in f:
                    if state == 'clazz' and line.find('## Functions')==0:
                        state = 'functions'
                        
                    elif (state == 'clazz' or state=='method' or state=='var' or state=='functions') and line.find('###')==0:
                        element = line.replace("const ### ","const ").split('###')[1].rstrip('#').strip(' ')
                        if element.find('(')!=-1 and element.find(')')!=-1:
                            method = parse_function(element)
                            clazzmethod = clazztosave.function_by_signature(method.name,method.returns,method.parameters)
                            state = 'method'
                        else:
                            state = 'var'
                    
                    elif (state == 'clazz' or state=='method' or state=='var' or state=='functions') and line.find('##')==0:
                        #print 'class: ' + line.strip('\n')
                        clazz_name = line.split('##')[1].rstrip('#').strip(' ').strip('\n')
                        clazz = getclass(clazz_name)
                        clazztosave = getclass(file_split[0])
                        if clazztosave.new:
                            clazztosave.module = os.path.basename(root)
                            print clazztosave.module
                        state = 'clazz'
                        print clazz_name + '\n\n'
                    
                    
                    elif state == 'clazz':
                        if line.find("//----------------------")==0:
                            continue
                        line = line.replace('```cpp','$$code(lang=c++)')
                        line = line.replace('```','$$/code')
                        print unicode(line,errors='ignore')
                        clazztosave.reference = clazztosave.reference + unicode(line, errors='ignore') #.decode('cp1252'))
                        
                    elif state == 'method':
                        if line.find("//----------------------")==0:
                            continue
                        line = line.replace('```cpp','$$code(lang=c++)')
                        line = line.replace('```','$$/code')
                        clazzmethod.description = clazzmethod.description + unicode(line, errors='ignore')
                    
                    elif state == 'function':
                        pass
                    elif state == 'functions' and line.find('###')==0:
                        pass
                    
                f.close()
                setclass(clazztosave)