def filelists_from_spec(spec, specpath): res = Tree() for pkg in spec.packages: name = "%s.install.in" % mappkgname.map_package_name(pkg.header) res.append("debian/%s" % name, files_from_pkg(spec.sourceHeader['name'], pkg, specpath)) return res
class TreeTest(unittest.TestCase): def setUp(self): self.t = Tree(0) self.val = 1 self.LEFT = 0 def append_test(self): self.t.append(self.val) self.assertEquals(self.val, self.t.ptr.children[0].data) def forward_test(self): self.t.append(self.val) self.t.forward(self.LEFT) self.assertEquals(self.val, self.t.ptr.data) def back_test(self): self.t.append(self.val) self.t.forward(self.LEFT) self.t.back() self.assertEquals(self.t.root, self.t.ptr) def reset_test(self): self.t.append(self.val) self.t.forward(self.LEFT) self.t.append(self.val) self.t.forward(self.LEFT) self.t.reset() self.assertEquals(self.t.root, self.t.ptr)
def t_LI(t): r'^\*\s(?P<text>.*)' text = t.lexer.lexmatch.group('text') node = Tree('listitem', text) node.append(token_node(t, type='para', value=text)) t.value = node return t
def p_doc(p): '''doc : sect1s | sect2s | sect3s | sect4s | sect5s | contents ''' doc = Tree('doc') for c in p[1]: doc.append(c) p[0] = doc
def t_OL(t): r'^(?P<n>\#|\d+)\.(?P<text>.*)' n = t.lexer.lexmatch.group('n') text = t.lexer.lexmatch.group('text') node = Tree('olistitem', text) node.append(token_node(t, type='para', value=text)) t.value = node if n != '#': t.value.number = int(n) else: t.value.number = '#' return t
def conffiles_from_spec(spec, specpath): # Configuration files, not to be overwritten on upgrade. # Files in /etc are automatically marked as config files, # so we only need to list files here if they are in a # different place. res = Tree() pkgname = mappkgname.map_package_name(spec.sourceHeader) files = rpmextra.files_from_spec(pkgname, specpath) if files.has_key( pkgname + "-%config" ): for filename in files[pkgname + "-%config"]: res.append('debian/conffiles', "%s\n" % filename) return res
def patches_from_spec(spec, src_dir): res = Tree() patches = [(seq, name) for (name, seq, typ) in spec.sources if typ == 2] patches = [name for (seq, name) in sorted(patches)] for patch in patches: with open(os.path.join(src_dir, patch)) as patchfile: contents = patchfile.read() permissions = os.fstat(patchfile.fileno()).st_mode res.append(os.path.join("debian/patches", patch), contents, permissions) res.append("debian/patches/series", "%s\n" % patch) return res
def p_sect_with_contents_and_quote(p): '''sect1 : H1 subdoc contents sect2s sect2 : H2 subdoc contents sect3s sect3 : H3 subdoc contents sect4s sect4 : H4 subdoc contents sect5s ''' quote = Tree('quote') for c in p[2]: quote.append(c) p[1].append(quote) for c in p[3]: p[1].append(c) for s in p[4]: p[1].append(s) p[1].timestamp = p[2] p[0] = p[1]
def p_sect_with_quote(p): '''sect1 : H1 subdoc contents | H1 subdoc sect2s sect2 : H2 subdoc contents | H2 subdoc sect3s sect3 : H3 subdoc contents | H3 subdoc sect4s sect4 : H4 subdoc contents | H4 subdoc sect5s sect5 : H5 subdoc contents ''' quote = Tree('quote') for c in p[2]: quote.append(c) p[1].append(quote) for c in p[3]: p[1].append(c) p[0] = p[1]
def changelog_from_spec(spec, isnative): res = Tree() hdr = spec.sourceHeader log = "" for (name, timestamp, text) in zip(hdr['changelogname'], hdr['changelogtime'], hdr['changelogtext']): # A Debian package's version is defined by the version of the # first entry in the changelog, so we must get this right. # Most spec files have changelog entries starting "First Last # <*****@*****.**> - version" - this seems to be the standard # for Red Hat spec files. # Some of our changelos only have "First Last <*****@*****.**>". # For these, we use the version from the spec. match = re.match( "^(.+) - (\S+)$", name ) if match: author = match.group(1) version = match.group(2) if isnative: version = re.sub('-', '.', version) else: author = name sep = '.' if isnative else '-' version = "%s%s%s" % (spec.sourceHeader['version'], sep, spec.sourceHeader['release']) print version package_name = mappkgname.map_package(hdr['name'])[0] log += "%s (%s) UNRELEASED; urgency=low\n" % (package_name, version) log += "\n" text = re.sub( "^-", "*", text, flags=re.MULTILINE ) text = re.sub( "^", " ", text, flags=re.MULTILINE ) log += "%s\n" % text log += "\n" date_string = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(int(timestamp))) log += " -- %s %s\n" % (author, date_string) log += "\n" res.append('debian/changelog', log) return res
def changelog_from_spec(spec, isnative): res = Tree() hdr = spec.sourceHeader log = "" for (name, timestamp, text) in zip(hdr['changelogname'], hdr['changelogtime'], hdr['changelogtext']): # A Debian package's version is defined by the version of the # first entry in the changelog, so we must get this right. # Most spec files have changelog entries starting "First Last # <*****@*****.**> - version" - this seems to be the standard # for Red Hat spec files. # Some of our changelos only have "First Last <*****@*****.**>". # For these, we use the version from the spec. match = re.match("^(.+) - (\S+)$", name) if match: author = match.group(1) version = match.group(2) if isnative: version = re.sub('-', '.', version) else: author = name sep = '.' if isnative else '-' version = "%s%s%s" % (spec.sourceHeader['version'], sep, spec.sourceHeader['release']) print version package_name = mappkgname.map_package(hdr['name'])[0] log += "%s (%s) UNRELEASED; urgency=low\n" % (package_name, version) log += "\n" text = re.sub("^-", "*", text, flags=re.MULTILINE) text = re.sub("^", " ", text, flags=re.MULTILINE) log += "%s\n" % text log += "\n" date_string = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(int(timestamp))) log += " -- %s %s\n" % (author, date_string) log += "\n" res.append('debian/changelog', log) return res
def testLoop(self): # No Loops input1 = Tree(children=TreeTest.tree_layout) input2 = Tree(children=TreeTest.tree_layout_2) input3 = Tree(children=TreeTest.tree_layout_3) self.assertFalse(input1.has_loop()) self.assertFalse(input2.has_loop()) self.assertFalse(input3.has_loop()) input1.append(input2) self.assertFalse(input1.has_loop()) # Loops input2.append(input1) input1.append(input2) self.assertTrue(input1.has_loop()) input4 = Tree(children=TreeTest.tree_layout) input5 = Tree(children=TreeTest.tree_layout_2) input6 = Tree(children=TreeTest.tree_layout_3) input6.append(input4) input4.append(input5) input5.append(input6) self.assertTrue(input4.has_loop()) self.assertTrue(input5.has_loop()) self.assertTrue(input6.has_loop())
from tree import Tree from linkedlists import Node from time import time import random head = Node() cur = head tree = Tree() for i in xrange(100): node = Node(i) cur.next = node cur = cur.next tree.append(random.randint(0,10000)) cur = head start = time() print "start linked list" while cur: print cur cur = cur.next linked_list_time = "linked list total time", time() - start print "tree start" start = time() tree.pretty_print() print linked_list_time print "tree end", time() - start
def p_simple_table(p): """table : lines COLSEP lines COLSEP""" # parse header row = None for l in p[1]: if row: vals = parse_row(p[2], l) for i in range(0, len(row)): row[i] += vals[i] else: row = parse_row(p[2], l) header = Tree("tr", "") for v in row: th = Tree("th", v) if len(v) > 0: para = parser_node(p, 1, ntype="para", value=v) th.append(para) header.append(th) table = Tree("table", "") table.append(header) # parse row for l in p[3]: r = Tree("tr", "") table.append(r) for v in parse_row(p[2], l): td = Tree("td", v) if len(v) > 0: para = parser_node(p, 1, ntype="para", value=v) td.append(para) # if type(v) in [str, unicode]: # para = parser_node(p, 1, ntype='para', value=v) # else: # raise 'v is not string, it is %s' % type(v) td.append(para) r.append(td) p[0] = table
def p_simple_table(p): '''table : lines COLSEP lines COLSEP''' # parse header row = None for l in p[1]: if row: vals = parse_row(p[2], l) for i in range(0, len(row)): row[i] += vals[i] else: row = parse_row(p[2], l) header = Tree('tr', '') for v in row: th = Tree('th', v) if len(v) > 0: para = parser_node(p, 1, ntype='para', value=v) th.append(para) header.append(th) table = Tree('table', '') table.append(header) # parse row for l in p[3]: r = Tree('tr', '') table.append(r) for v in parse_row(p[2], l): td = Tree('td', v) if len(v) > 0: para = parser_node(p, 1, ntype='para', value=v) td.append(para) #if type(v) in [str, unicode]: # para = parser_node(p, 1, ntype='para', value=v) #else: # raise 'v is not string, it is %s' % type(v) td.append(para) r.append(td) p[0] = table
def copyright_from_spec(_spec): res = Tree() res.append("debian/copyright", "FIXME") return res
def format_from_spec(_spec, isnative): res = Tree() fmt = "native" if isnative else "quilt" res.append("debian/source/format", "3.0 (%s)\n" % fmt) return res
def compat_from_spec(_spec): res = Tree() res.append("debian/compat", "8") return res
'MPhone': items.get('MPhone'), 'OrgName': items.get('OrgName'), 'Position': items.get('Position'), 'Tel': items.get('Tel'), 'City': items.get('City'), 'Email': items.get('Email'), 'WorkPlaceName': items.get('WorkPlaceName'), } lists.append(item) return lists T = Tree() stack_list = [] node = Node({'name': '沈'}) T.append(node, 'admin') XML = get_page('afbbd9ea-7568-4cbb-ad7d-a49acc5dd3a7') result = parse_page(XML) for i in result: i['superior'] = node.name i['subordinate'] = [] data = Node(i) stack_list.append(data) T.append(data, node.name) try: while len(stack_list) > 0: print(len(stack_list)) note = stack_list[0] XML = get_page(note.id) result = parse_page(XML)