コード例 #1
0
def get_filename(event):
    global result
    filename = entry.get()
    try:
        result = docstrings.get_docstrings(filename)
    except FileNotFoundError:
        filename = entry.get()
        result = docstrings.get_docstrings(filename)
    entry.destroy()
    button_ok.destroy()
    button_module = Button(tree,
                           text=filename,
                           background='PaleVioletRed1',
                           activebackground='PaleVioletRed3',
                           command=partial(get_docstring, result['.']))
    button_module.place(x=10, y=10)
    tree.create_line(10, 10, 10, 10 + 50)
    tree.create_line(10, 60, 10 + 200, 60)
    previousclass = ''
    x = 210
    y = 60
    for k, v in result.items():
        if k == '.':
            continue
        num = k.find('.')
        if previousclass == k[:num]:
            button_def = Button(tree,
                                text=k[num + 1:],
                                background='aquamarine2',
                                activebackground='aquamarine4',
                                command=partial(get_docstring, v))
            button_def.place(x=x, y=y)
            tree.create_line(x - 100, y - 50, x - 100, y)
            tree.create_line(x - 100, y, x, y)
            y += 50
        elif previousclass != k[:num]:
            x -= 100
            button_class = Button(tree,
                                  text=k[:num],
                                  background='MediumPurple2',
                                  activebackground='MediumPurple4',
                                  command=partial(get_docstring, v))
            button_class.place(x=x, y=y)
            tree.create_line(x - 100, 10, x - 100, y)
            tree.create_line(x - 100, y, x, y)
            x += 100
            y += 50
            button_def = Button(tree,
                                text=k[num + 1:],
                                background='aquamarine2',
                                activebackground='aquamarine4',
                                command=partial(get_docstring, v))
            button_def.place(x=x, y=y)
            tree.create_line(x - 100, y - 50, x - 100, y)
            tree.create_line(x - 100, y, x, y)
            y += 50
            previousclass = k[:num]
コード例 #2
0
 def test_get_docstrings_module_with_comments(self):
     result = d.get_docstrings('example.txt')
     s = []
     for key in result.keys():
         if key[:key.find('.')] == '' and key[key.find('.') + 1:] == '':
             s.append('.')
     self.assertTrue(len(s) == 1)
コード例 #3
0
 def test_get_docstrings_class_with_comments(self):
     result = d.get_docstrings('example.txt')
     s = set()
     for key in result.keys():
         if key[:key.find('.')] != '' and key[key.find('.') + 1:] == '':
             s.add(key[:key.find('.')])
     self.assertTrue(len(s) == 2)
コード例 #4
0
def get_pdf(filename):
    d = docstrings.get_docstrings(filename)
    pdf = pyFPDF.FPDF(format='letter')
    pdf.add_page()
    for i, j in d.items():
        pdf.set_font("Arial", size=14)
        pdf.cell(0, 5, 'class.def: {0}'.format(i), border=1, ln=1, align='C')
        arr = j.split('\n')
        pdf.cell(0, 5, 'comm:', border=0, ln=1)
        pdf.set_font("Arial", size=12)
        for el in arr:
            pdf.cell(0, 5, el, border=0, ln=1)
    name_pdf = '{0}.pdf'.format(filename.split('.')[0])
    pdf.output(name_pdf)

    f_pdf_read = open(name_pdf, 'rb')
    read = PdfFileReader(f_pdf_read)
    write = PdfFileWriter()
    for i in range(read.getNumPages()):
        page = read.getPage(i)
        page_content = page.extractText()
        names = re.findall(r'(class\.def: [\w()]*\.\w*)', page_content)
        write.addPage(read.getPage(i))
        for name in names:
            write.addBookmark(re.sub(r'(class\.def: )|(comm)', '', name),
                              i,
                              bold=True)
    f_pdf_write = open(name_pdf, 'wb')
    write.write(f_pdf_write)
    f_pdf_read.close()
    f_pdf_write.close()
コード例 #5
0
 def test_get_docstrings_pdf_comm(self):
     docstrings = d.get_docstrings('example.txt')
     f_pdf_read = open('example.pdf', 'rb')
     read = PdfFileReader(f_pdf_read)
     res = ''
     for i in range(read.getNumPages()):
         page = read.getPage(i)
         page_content = page.extractText()
         res += page_content
     for e in docstrings:
         self.assertTrue(res.find(e) != -1)
     f_pdf_read.close()
コード例 #6
0
 def test_get_docstrings_pdf_def(self):
     docstrings = d.get_docstrings('example.txt')
     f_pdf_read = open('example.pdf', 'rb')
     read = PdfFileReader(f_pdf_read)
     res = []
     for i in range(read.getNumPages()):
         page = read.getPage(i)
         page_content = page.extractText()
         names = re.findall(r'(class\.def: [\w()]*\.\w*)', page_content)
         for name in names:
             newname = name.replace('comm', '')
             newname = newname[newname.find('class.def: ') + 11:]
             res.append(newname)
     self.assertTrue(len(res) == len(docstrings))
     for e in res:
         self.assertTrue(e in docstrings)
     f_pdf_read.close()
コード例 #7
0
 def test_get_docstrings_none(self):
     result = d.get_docstrings('example.txt')
     self.assertIsNotNone(result)