Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes at line:145 in scholar2xbundle.py #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions scholar2xbundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,25 @@ def add_pdf_link_to_vert(self, pdffn, text, vert):
html = etree.XML('<html><a href="%s">%s</a></html>' % (newpath, dn))
print " html link: %s = %s" % (dn, newpath)
vert.append(html)


def add_py_link_to_vert(self, pyfn, text, vert):
'''
Add <html> with link to PY file to vertical
'''
newpath = self.fix_static('../' + pyfn)
dn = text.strip()
html = etree.XML('<html><a href="%s">%s</a></html>' % (newpath, dn))
print " html link: %s = %s" % (dn, newpath)
vert.append(html)
def add_txt_link_to_vert(self, txtfn, text, vert):
'''
Add <html> with link to txt file to vertical
'''
newpath = self.fix_static('../' + txtfn)
dn = text.strip()
html = etree.XML('<html><a href="%s">%s</a></html>' % (newpath, dn))
print " html link: %s = %s" % (dn, newpath)
vert.append(html)

def add_contents_to_vert(self, vxml, vert):
'''
Expand All @@ -134,6 +152,12 @@ def add_contents_to_vert(self, vxml, vert):
if vfn.endswith('.pdf'):
self.add_pdf_link_to_vert(vfn, vxml.text, vert)
return
if vfn.endswith('.py'):
self.add_py_link_to_vert(vfn, vxml.text, vert)
return
if vfn.endswith('.txt'):
self.add_txt_link_to_vert(vfn, vxml.text, vert)
return

# process html file
try:
Expand All @@ -142,7 +166,7 @@ def add_contents_to_vert(self, vxml, vert):
except Exception as err:
print " ERROR reading %s: %s" % (fn, err)
return
nav = vcontents.find('.//div[@id="parent-fieldname-text"]') # v.find('.//p[@class="sc_nav"]')
nav = vcontents.find('.//div[@id="course_inner_section"]')
html = etree.SubElement(vert,'html')
html.set('display_name',vert.get('display_name','Page'))
for p in nav:
Expand Down
2 changes: 2 additions & 0 deletions xbundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ def write_xml(x):
elem.attrib.pop('url_name')
if 'url_name_orig' in elem.attrib and self.keep_urls:
elem.attrib.pop('url_name_orig')
if un.__len__() > 182:
un = un[:182-un.__len__()]
edir = self.mkdir(self.dir / x.tag)
open(edir/un + '.xml','w').write(self.pp_xml(x))
return un
Expand Down