Skip to content
Permalink
f5215298d6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
670 lines (658 sloc) 44.8 KB
# -*- codING: utf-8 -*-
__author__ = 'kai'
from django.core.management.base import BaseCommand
from django.conf import settings
from publications.models import *
import ConfigParser
import os
import shutil
from lxml import etree
from PIL import Image
import shlex
import subprocess
"""
export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages"
"""
class Command(BaseCommand):
help = "RTFM!"
# process as string to be used to create html text for elements
def process_as_string(self,xmlElement):
strResult = xmlElement.text or ""
for xmlChild in xmlElement.iterchildren():
strResult = strResult + etree.tostring(xmlChild)
return strResult
def process_index_entries(self,xmlIndex,xmlElement,Newelement,Newpublication):
for xmlEntry in xmlElement.findall('EOAindex'):
if xmlEntry.get("secondary") is not None:
continue
Newindexelement = Indexelement(Element=Newelement)
strMainEntry = xmlEntry.get("main")
strHtml = strMainEntry + ": "
# Find corresponding Entry in EOAprintindex
for xmlIndexEntry in xmlIndex.findall(".//EOAindexentry"):
if xmlIndexEntry.get("main") == strMainEntry:
intLinkNumber = 1
for xmlIndexLink in xmlIndexEntry.findall("./EOAindexlink"):
strHtml = strHtml + "<a href='/" + Newpublication.Serie.lower() + "/" + \
Newpublication.Number + "/" + xmlIndexLink.get("chapterorder") + "/index.html#"\
+ xmlIndexLink.get('elementorder') + "'>"
strHtml = strHtml + str(intLinkNumber)
strHtml = strHtml + "</a> "
intLinkNumber += 1
strHtml = strHtml + "<br/>"
Newindexelement.Html = strHtml
Newindexelement.save()
def process_personindex_entries(self,xmlPersonindex,xmlElement,Newelement,Newpublication):
for xmlEntry in xmlElement.findall('EOAindexperson'):
if xmlEntry.get("secondary") is not None:
continue
Newindexelement = Indexelement(Element=Newelement)
strMainEntry = xmlEntry.get("main")
if xmlEntry.get("display") is not None:
strHtml = xmlEntry.get("display") + ": "
else:
strHtml = xmlEntry.get("main") + ": "
# Find corresponding Entry in EOAprintindex
for xmlIndexEntry in xmlPersonindex.findall(".//EOAindexentry"):
if xmlIndexEntry.get("main") == strMainEntry:
intLinkNumber = 1
for xmlIndexLink in xmlIndexEntry.findall("./EOAindexlink"):
strHtml = strHtml + "<a href='/" + Newpublication.Serie.lower() + "/" + \
Newpublication.Number + "/" + xmlIndexLink.get("chapterorder") + "/index.html#"\
+ xmlIndexLink.get('elementorder') + "'>"
strHtml = strHtml + str(intLinkNumber)
strHtml = strHtml + "</a> "
intLinkNumber += 1
strHtml = strHtml + "<br/>"
Newindexelement.Html = strHtml
Newindexelement.save()
def process_locationindex_entries(self,xmlLocationindex,xmlElement,Newelement,Newpublication):
for xmlEntry in xmlElement.findall('EOAindexlocation'):
if xmlEntry.get("secondary") is not None:
continue
Newindexelement = Indexelement(Element=Newelement)
strMainEntry = xmlEntry.get("main")
if xmlEntry.get("display") is not None:
strHtml = xmlEntry.get("display") + ": "
else:
strHtml = xmlEntry.get("main") + ": "
# Find corresponding Entry in EOAprintindex
for xmlIndexEntry in xmlLocationindex.findall(".//EOAindexentry"):
if xmlIndexEntry.get("main") == strMainEntry:
intLinkNumber = 1
for xmlIndexLink in xmlIndexEntry.findall("./EOAindexlink"):
strHtml = strHtml + "<a href='/" + Newpublication.Serie.lower() + "/" + \
Newpublication.Number + "/" + xmlIndexLink.get("chapterorder") + "/index.html#"\
+ xmlIndexLink.get('elementorder') + "'>"
strHtml = strHtml + str(intLinkNumber)
strHtml = strHtml + "</a> "
intLinkNumber += 1
strHtml = strHtml + "<br/>"
Newindexelement.Html = strHtml
print ("Index Entry for Location Processed:")
print(strHtml)
Newindexelement.save()
print (xmlEntry.get("main"))
return
def handle(self, **options):
# Get current directory, and append /import
strDir = os.getcwd() + '/website/import'
# Read .cfg-File
cfgPublication = ConfigParser.RawConfigParser()
cfgPublication.read(strDir + '/publication.cfg')
# Setup and prepare the publication
Newpublication = Publication(Published=False)
Newpublication.Serie = cfgPublication.get('Technical', 'Serie').lower()
Newpublication.Number = cfgPublication.get('Technical', 'Number')
Newpublication.Title = cfgPublication.get('Technical', 'Title')
Newpublication.Subtitle = cfgPublication.get('Technical', 'Subtitle')
Newpublication.Datepublished = cfgPublication.get('Technical', 'PublicationDate')
Newpublication.Language = cfgPublication.get('Technical', 'Language')
Newpublication.Publicationlicense = cfgPublication.get('Technical', 'License')
Newpublication.Isbn = cfgPublication.get('Technical', 'ISBN')
Newpublication.Price = cfgPublication.get('Technical', 'Price')
Newpublication.Shoplink = cfgPublication.get('Technical', 'Shoplink')
Newpublication.Descriptionlong = cfgPublication.get('General', 'DetailedDescription')
Newpublication.Descriptionshort = cfgPublication.get('General', 'BriefDescription')
Newpublication.Submitter = cfgPublication.get('General', 'Submitter')
Newpublication.Editorialcoordination = cfgPublication.get('General', 'EditorialCoordination')
Newpublication.Copyeditor = cfgPublication.get('General', 'Copyediting')
Newpublication.Translator = cfgPublication.get('General', 'Translator')
Newpublication.Dedication = cfgPublication.get('General', 'Dedication')
if cfgPublication.get('Authors', 'Author1'):
Newpublication.Publicationauthor1 = cfgPublication.get('Authors', 'Author1')
if cfgPublication.get('Authors', 'Author2'):
Newpublication.Publicationauthor2 = cfgPublication.get('Authors', 'Author2')
if cfgPublication.get('Authors', 'Author3'):
Newpublication.Publicationauthor3 = cfgPublication.get('Authors', 'Author3')
if cfgPublication.get('Authors', 'Author4'):
Newpublication.Publicationauthor4 = cfgPublication.get('Authors', 'Author4')
if cfgPublication.get('Authors', 'Author5'):
Newpublication.Publicationauthor5 = cfgPublication.get('Authors', 'Author5')
if cfgPublication.get('Authors', 'Zusatz'):
Newpublication.Publicationauthorsuffix = cfgPublication.get('Authors', 'Zusatz')
# Create Media-Directory for this publication
if os.path.exists(settings.MEDIA_ROOT + cfgPublication.get('Technical', 'Serie')) == False:
os.mkdir(settings.MEDIA_ROOT + cfgPublication.get('Technical', 'Serie'))
os.mkdir(settings.MEDIA_ROOT + cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number'))
import_files_dir = settings.MEDIA_ROOT + cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number') + os.path.sep + "import_files"
strMediaDir = settings.MEDIA_ROOT + cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number')
os.mkdir(strMediaDir + "/embedded")
# Copy and prepare Cover Images
shutil.copy(strDir + "/Cover.jpg", strMediaDir)
Newpublication.Coverbig = cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number') + "/Cover.jpg"
tmpImageObject = Image.open(settings.MEDIA_ROOT + str(Newpublication.Coverbig))
Newpublication.Coverbigwidth = tmpImageObject.size[0]
Newpublication.Coverbigheight = tmpImageObject.size[1]
shutil.copy(strDir + "/Cover.jpg", strMediaDir + "/Cover_medium.jpg")
strCommand = "/usr/bin/gm convert -resize 250x " + strMediaDir + "/Cover_medium.jpg " + strMediaDir + "/Cover_medium.jpg"
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newpublication.Covermedium = cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number') + "/Cover_medium.jpg"
tmpImageObject = Image.open(settings.MEDIA_ROOT + str(Newpublication.Covermedium))
Newpublication.Covermediumwidth = tmpImageObject.size[0]
Newpublication.Covermediumheight = tmpImageObject.size[1]
shutil.copy(strDir + "/Cover.jpg", strMediaDir + "/Cover_small.jpg")
strCommand = "/usr/bin/gm convert -resize 140x " + strMediaDir + "/Cover_small.jpg " + strMediaDir + "/Cover_small.jpg"
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newpublication.Coversmall = cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number') + "/Cover_small.jpg"
tmpImageObject = Image.open(settings.MEDIA_ROOT + str(Newpublication.Coversmall))
Newpublication.Coversmallwidth = tmpImageObject.size[0]
Newpublication.Coversmallheight = tmpImageObject.size[1]
shutil.copy(strDir + "/Cover.jpg", strMediaDir + "/Cover_smallright.jpg")
strCommand = "/usr/bin/gm convert -resize 180x " + strMediaDir + "/Cover_smallright.jpg " + strMediaDir + "/Cover_smallright.jpg"
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newpublication.Coversmallright = cfgPublication.get('Technical', 'Serie') + "/"+ cfgPublication.get('Technical', 'Number') + "/Cover_smallright.jpg"
tmpImageObject = Image.open(settings.MEDIA_ROOT + str(Newpublication.Coversmallright))
Newpublication.Coversmallrightwidth = tmpImageObject.size[0]
Newpublication.Coversmallrightheight = tmpImageObject.size[1]
# Publication is not featured by default
Newpublication.Featured = False
# Save the publication
Newpublication.save()
# Open Django.xml and process the XML
xmlParser = etree.XMLParser(no_network=True,load_dtd=True)
xmlTree = etree.parse(strDir + "/Django.xml", xmlParser)
xmlChapters = xmlTree.findall("EOAchapter")
for xmlChapter in xmlChapters:
Newchapter = Chapter(Publication=Newpublication)
Newchapter.Order = xmlChapter.get("order")
if xmlChapter.get("language") is not None:
Newchapter.Chapterlanguage = xmlChapter.get("language")
os.mkdir(strMediaDir + "/" + xmlChapter.get('order'))
if xmlChapter.get("number") != "":
Newchapter.Number = xmlChapter.get("number")
if xmlChapter.find(".//EOAparthtml") is not None:
xmlEOAparthtml = xmlChapter.find(".//EOAparthtml")
Newchapter.Chapterpart = self.process_as_string(xmlEOAparthtml)
xmlEOAparthtml.getparent().remove(xmlEOAparthtml)
if xmlChapter.find(".//EOAauthor") is not None:
if len(xmlChapter.findall(".//EOAauthor")) >= 1:
Newchapter.Chapterauthor1 = self.process_as_string(xmlChapter.findall(".//EOAauthor")[0])
if len(xmlChapter.findall(".//EOAauthor")) >= 2:
Newchapter.Chapterauthor2 = self.process_as_string(xmlChapter.findall(".//EOAauthor")[1])
if len(xmlChapter.findall(".//EOAauthor")) >= 3:
Newchapter.Chapterauthor3 = self.process_as_string(xmlChapter.findall(".//EOAauthor")[2])
if len(xmlChapter.findall(".//EOAauthor")) >= 4:
Newchapter.Chapterauthor4 = self.process_as_string(xmlChapter.findall(".//EOAauthor")[3])
if len(xmlChapter.findall(".//EOAauthor")) >= 5:
Newchapter.Chapterauthor5 = self.process_as_string(xmlChapter.findall(".//EOAauthor")[4])
for xmlAuthor in xmlChapter.findall(".//EOAauthor"):
xmlAuthor.getparent().remove(xmlAuthor)
Newchapter.Title = self.process_as_string(xmlChapter.find("head"))
Newchapter.Chapterauthor1profile = False
Newchapter.Chapterauthor2profile = False
Newchapter.Chapterauthor3profile = False
Newchapter.Chapterauthor4profile = False
Newchapter.Chapterauthor5profile = False
Newchapter.save()
# Inline-Equation (EOAineq) need to be prepared first
xmlInlineEquations = xmlChapter.findall(".//img")
for xmlInlineEquation in xmlInlineEquations:
if xmlInlineEquation.get("class") == "EOAineq":
strEquationImage = xmlInlineEquation.get('src')
shutil.copy(strDir + "/images/" + strEquationImage, strMediaDir + "/" + xmlChapter.get('order') + "/")
strNewEquationImage = "/media/" + cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlChapter.get('order') + "/" + strEquationImage
xmlInlineEquation.set('src', strNewEquationImage)
for xmlChild in xmlChapter.iterchildren():
Newelement = Element(Publication=Newpublication,Chapter=Newchapter)
Newelement.Indentation = False
print (xmlChild.tag)
# Process any embedded figurenonumbers yet ignoring already processed EOAineqs
xmlFigures = xmlChild.findall(".//img")
if xmlFigures is not None:
for xmlFigure in xmlFigures:
strFileName = xmlFigure.get("src")
if "EOAineq" in strFileName:
continue
if "EOAchem" in strFileName:
continue
if xmlFigure.getparent().tag == "td":
shutil.copy(strDir + "/images/" + strFileName, strMediaDir + "/" + xmlChapter.get('order') + "/")
strTableImage = "/media/" + cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlChapter.get('order') + "/" + strFileName
xmlFigure.set('src', strTableImage)
continue
shutil.copy(strDir + "/images/embedded/" + strFileName, strMediaDir + "/embedded/" + strFileName)
xmlFigure.set("src", "/media/" + cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/embedded/" + strFileName)
if xmlChild.tag == "EOAparagraph" and xmlChild.get("rend") != "quoted":
Newelement.Kind = 'eoaparagraph'
Newelement.Order = xmlChild.get('order')
Newelement.Fulltext = self.process_as_string(xmlChild)
if xmlChild.get("style") == "box":
Newelement.Boxed = True
Newelement.save()
if xmlChild.tag == "EOAparagraph" and xmlChild.get("rend") == "quoted":
Newelement.Kind = 'eoaquotedparagraph'
Newelement.Order = xmlChild.get('order')
Newelement.Fulltext = self.process_as_string(xmlChild)
Newelement.save()
if xmlChild.tag == "EOAsection":
Newelement.Kind = 'eoasection'
Newelement.Order = xmlChild.get('order')
Newelement.Fulltext = self.process_as_string(xmlChild.find('head'))
if xmlChild.get("number") is not None:
Newelement.Number = xmlChild.get("number")
Newelement.save()
if xmlChild.tag == "EOAsubsection":
Newelement.Kind = 'eoasubsection'
Newelement.Order = xmlChild.get('order')
Newelement.Fulltext = self.process_as_string(xmlChild.find('head'))
if xmlChild.get("number") is not None:
Newelement.Number = xmlChild.get("number")
Newelement.save()
if xmlChild.tag == "EOAsubsubsection":
Newelement.Kind = 'eoasubsubsection'
Newelement.Order = xmlChild.get('order')
Newelement.Fulltext = self.process_as_string(xmlChild.find('head'))
if xmlChild.get("number") is not None:
Newelement.Number = xmlChild.get("number")
Newelement.save()
if xmlChild.tag == "EOAfigure":
Newelement.Kind = 'eoafigure'
Newelement.Order = xmlChild.get('order')
Newelement.Number = xmlChild.get('number')
hielement_string = xmlChild.get('hielement')
if hielement_string is not None:
# Newelement.HIElement = hielement_string
hi_caption = xmlChild.find('caption')
if hi_caption is not None:
Newelement.Caption = self.process_as_string(xmlChild.find('caption'))
else:
Newelement.Caption = ""
else:
# Newelement.HIElement = ""
Newelement.Caption = self.process_as_string(xmlChild.find('caption'))
# Newelement.Caption = self.process_as_string(xmlChild.find('caption'))
strFigureImage = xmlChild.get('file')
print ("Converting Image File:")
print (strFigureImage)
shutil.copy(strDir + "/images/" + strFigureImage, strMediaDir + "/" + xmlChapter.get('order') + "/")
strCommand = "/usr/bin/gm convert -resize 1500x900 " + strMediaDir + "/" + xmlChapter.get('order') + "/" + strFigureImage + " " + strMediaDir + "/" + xmlChapter.get('order') + "/big" + strFigureImage
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newelement.Figureimagebig = cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlChapter.get('order') + "/big" + strFigureImage
strCommand = "/usr/bin/gm convert -resize 530x400 " + strMediaDir + "/" + xmlChapter.get('order') + "/" + strFigureImage + " " + strMediaDir + "/" + xmlChapter.get('order') + "/" + strFigureImage
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newelement.Figureimagenormal = cfgPublication.get('Technical', 'Serie') +\
"/"+ cfgPublication.get('Technical', 'Number')\
+ "/" + xmlChapter.get('order') + "/" + strFigureImage
Newelement.save()
if xmlChild.tag == "EOAfigurenonumber":
Newelement.Kind = 'eoafigure'
Newelement.Order = xmlChild.get('order')
strFigureImage = xmlChild.get('file')
shutil.copy(strDir + "/images/" + strFigureImage, strMediaDir + "/" + xmlChapter.get('order') + "/")
strCommand = "/usr/bin/gm convert -resize 1500x900 " + strMediaDir + "/" + xmlChapter.get('order') + "/" + strFigureImage + " " + strMediaDir + "/" + xmlChapter.get('order') + "/big" + strFigureImage
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newelement.Figureimagebig = cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlChapter.get('order') + "/big" + strFigureImage
strCommand = "/usr/bin/gm convert -resize 530x400 " + strMediaDir + "/" + xmlChapter.get('order') + "/" + strFigureImage + " " + strMediaDir + "/" + xmlChapter.get('order') + "/" + strFigureImage
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newelement.Figureimagenormal = cfgPublication.get('Technical', 'Serie') +\
"/"+ cfgPublication.get('Technical', 'Number')\
+ "/" + xmlChapter.get('order') + "/" + strFigureImage
Newelement.save()
if xmlChild.tag == "EOAequation":
Newelement.Kind = 'eoaequation'
Newelement.Order = xmlChild.get('order')
Newelement.Number = xmlChild.get('number')
strFilename = xmlChild.get('filename')
shutil.copy(strDir + "/images/" + strFilename, strMediaDir + "/" + xmlChapter.get('order') + "/")
Newelement.Genericimage = cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlChapter.get('order') + "/" + strFilename
Newelement.Texcode = xmlChild.get('TeX')
Newelement.save()
if xmlChild.tag == "EOAtranscription":
Newelement.Kind = 'eoatranscription'
Newelement.Order = xmlChild.get('order')
Newelement.Transcriptionleftheader = self.process_as_string(xmlChild.find('Leftheader'))
Newelement.Transcriptionrightheader = self.process_as_string(xmlChild.find('Rightheader'))
Newelement.Transcriptionleftpage = self.process_as_string(xmlChild.find('EOAtranscriptionleft'))
Newelement.Transcriptionrightpage = self.process_as_string(xmlChild.find('EOAtranscriptionright'))
Newelement.save()
if xmlChild.tag == "EOAtheorem":
Newelement.Kind = 'eoatheorem'
Newelement.Order = xmlChild.get('order')
Newelement.Number = xmlChild.get('number')
Newelement.Theoremtitle = self.process_as_string(xmlChild.find('head'))
Newelement.Theoremdescription = self.process_as_string(xmlChild.find('p'))
Newelement.save()
if xmlChild.tag == "EOAdescription":
Newelement.Kind = 'eoadescription'
Newelement.Order = xmlChild.get('order')
xmlDescription = xmlChild.find('description')
Newelement.Caption = self.process_as_string(xmlDescription)
xmlDescription.getparent().remove(xmlDescription)
Newelement.Fulltext = self.process_as_string(xmlChild.find('p'))
Newelement.save()
if xmlChild.tag == "EOAletterhead":
Newelement.Kind = 'eoaletterhead'
Newelement.Order = xmlChild.get('order')
Newelement.Letterrecipient = self.process_as_string(xmlChild.find('Recipient'))
Newelement.Letteradditional = self.process_as_string(xmlChild.find('Additional'))
Newelement.Letterarchive = self.process_as_string(xmlChild.find('Archive'))
Newelement.Letterpages = self.process_as_string(xmlChild.find('Pages'))
Newelement.save()
if xmlChild.tag == "EOAtable":
Newelement.Kind = 'eoatable'
Newelement.Order = xmlChild.get('order')
if xmlChild.get('number'):
Newelement.Number = xmlChild.get('number')
if xmlChild.find('EOAtablecaption') is not None:
Newelement.Caption = self.process_as_string(xmlChild.find('EOAtablecaption'))
Newelement.Tablehtml = self.process_as_string(xmlChild.find('table'))
Newelement.Tablewidth = xmlChild.find('table').get('width')
Newelement.save()
if xmlChild.tag == "EOAfootnote":
Newelement.Kind = 'eoafootnote'
Newelement.Order = xmlChild.get('order')
# Copy and adjust embedded EOAequationnonumber
xmlEquations = xmlChild.findall(".//EOAequationnonumber")
for xmlEquation in xmlEquations:
strFilename = xmlEquation.get("filename")
strTexcode = xmlEquation.get("TeX")
xmlEquation.tag = "p"
del xmlEquation.attrib["TeX"]
del xmlEquation.attrib["filename"]
xmlImg = etree.Element("img")
shutil.copy(strDir + "/images/" + strFilename, strMediaDir + "/" + xmlChapter.get('order') + "/")
xmlImg.set("src", "/media/" + cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlChapter.get('order') + "/" + strFilename)
xmlImg.set("TeX", strTexcode)
xmlEquation.append(xmlImg)
Newelement.Number = xmlChild.get('number')
Newelement.Listcharacter = xmlChild.get('anchor')
Newelement.Fulltext = self.process_as_string(xmlChild)
Newelement.save()
if xmlChild.get("listtype") == "ordered":
Newelement.Indentation = True
Newelement.Listcharacter = xmlChild.get("listnumber")
Newelement.save()
if xmlChild.get("indent") is not None:
Newelement.Indentation = True
Newelement.save()
if xmlChild.findall("EOAindex") is not None:
xmlEOAindex = xmlTree.find(".//EOAprintindex")
if xmlEOAindex is not None:
self.process_index_entries(xmlEOAindex,xmlChild,Newelement,Newpublication)
if xmlChild.findall("EOAindexperson") is not None:
xmlEOApersonindex = xmlTree.find(".//EOAprintpersonindex")
if xmlEOApersonindex is not None:
self.process_personindex_entries(xmlEOApersonindex,xmlChild,Newelement,Newpublication)
if xmlChild.findall("EOAindexlocation") is not None:
xmlEOAlocationindex = xmlTree.find(".//EOAprintlocationindex")
if xmlEOAlocationindex is not None:
self.process_locationindex_entries(xmlEOAlocationindex,xmlChild,Newelement,Newpublication)
xmlFacsimileparts = xmlTree.findall("EOAfacsimilepart")
for xmlFacsimilepart in xmlFacsimileparts:
print("Process Facsimileparts")
Newchapter = Chapter(Publication=Newpublication)
Newchapter.Order = xmlFacsimilepart.get("order")
os.mkdir(strMediaDir + "/" + xmlFacsimilepart.get('order'))
Newchapter.Title = self.process_as_string(xmlFacsimilepart.find("head"))
Newchapter.Facsimile = True
Newchapter.save()
xmlFacsimilepages = xmlFacsimilepart.findall("EOAfacsimilepage")
for xmlFacsimilepage in xmlFacsimilepages:
Newelement = Element(Publication=Newpublication,Chapter=Newchapter)
Newelement.Kind = 'eoafacsimilepage'
Newelement.Order = xmlFacsimilepage.get('order')
if xmlFacsimilepage.get('pagenumber') is not None:
Newelement.Caption = xmlFacsimilepage.get('pagenumber')
strFilename = xmlFacsimilepage.get('file')
shutil.copy(strDir + "/images/" + strFilename, strMediaDir + "/" + xmlFacsimilepart.get('order') + "/")
Newelement.Figureimagebig = cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlFacsimilepart.get('order') + "/" + strFilename
# Process Figureimagenormal
strCommand = "/usr/bin/gm convert -resize 535x1700 " + strMediaDir + "/" + xmlFacsimilepart.get('order') + "/" + strFilename + " " + strMediaDir + "/" + xmlFacsimilepart.get('order') + "/normal" + strFilename
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newelement.Figureimagenormal = cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlFacsimilepart.get('order') + "/normal" + strFilename
# Process Genericimage for Thumbnail
strCommand = "/usr/bin/gm convert -resize 170x300 " + strMediaDir + "/" + xmlFacsimilepart.get('order') + "/" + strFilename + " " + strMediaDir + "/" + xmlFacsimilepart.get('order') + "/tn" + strFilename
listArguments = shlex.split(strCommand)
subprocess.call(listArguments, shell=False)
Newelement.Genericimage = cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlFacsimilepart.get('order') + "/tn" + strFilename
# Process additional Facsimile-Information if available
tmpElements = xmlFacsimilepage.findall("EOAfacsimileelement")
if tmpElements:
for tmpElement in tmpElements:
# Fix embedded img-Tags to produce the correct link, and copy the embedded image
for xmlChild in tmpElement.iterdescendants():
if xmlChild.tag == 'img':
print ("Image im Facsimile gefunden")
strFilename = xmlChild.get("src")
print (strDir + "/" + strFilename)
shutil.copy(strDir + "/images/" + strFilename, strMediaDir + "/" + xmlFacsimilepart.get('order') + "/")
strFilepath = "/media/" + cfgPublication.get('Technical', 'Serie') + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlFacsimilepart.get('order') + "/" + strFilename
xmlChild.set('src', strFilepath)
if tmpElement.get('type') == 'text':
Newelement.Facsimiletext = self.process_as_string(tmpElement)
if tmpElement.get('type') == 'textPollux':
Newelement.Facsimilepollux = self.process_as_string(tmpElement)
if tmpElement.get('type') == 'xml':
Newelement.Facsimilexml = self.process_as_string(tmpElement)
Newelement.save()
xmlIndex = xmlTree.find(".//EOAprintindex")
if xmlIndex is not None:
xmlIndexsections = xmlIndex.findall(".//EOAindexsection")
intObjectOrder = 1
intIndexEntry = 1
for xmlIndexsection in xmlIndexsections:
Newindexsection = Indexsection(Publication=Newpublication)
Newindexsection.Kind = 'keyword'
Newindexsection.Title = xmlIndexsection.get("Character")
Newindexsection.Order = intObjectOrder
intObjectOrder += 1
strResult = "<div class=\"accordion\" id=\"accordion" + str(intObjectOrder) + "\">"
for xmlIndexEntry in xmlIndexsection.iterchildren():
strIndexHtml = """<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion"""
strIndexHtml = strIndexHtml + str(intIndexEntry) + "\" href=\"#" + "indexentry" + str(intIndexEntry) + "\">"
if xmlIndexEntry.get('display') is not None:
strIndexHtml = strIndexHtml + unicode(xmlIndexEntry.get('display'))
else:
strIndexHtml = strIndexHtml + str(xmlIndexEntry.get('main'))
strIndexHtml = strIndexHtml + """</a></div> <div id="""
strIndexHtml = strIndexHtml + "\"indexentry" + str(intIndexEntry) + "\""
strIndexHtml = strIndexHtml + """ class="accordion-body collapse"><div class="accordion-inner">"""
# Process Links of the main entry
intMainIndexLinkNumber = 1
for xmlIndexlink in xmlIndexEntry.findall("./EOAindexlink"):
strIndexLink = "<a href=\"/" + Newpublication.Serie.lower() + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlIndexlink.get('chapterorder') + "/index.html#" + xmlIndexlink.get('elementorder') + "\">"
strIndexLink = strIndexLink + str(intMainIndexLinkNumber) + "</a> "
if xmlIndexlink.get('bold') == "True":
strIndexLink = "<strong>" + strIndexLink + "</strong>"
strIndexHtml = strIndexHtml + strIndexLink
intMainIndexLinkNumber += 1
# Process Subentries if available
for xmlIndexSubEntry in xmlIndexEntry.findall(".//EOAindexsubentry"):
if xmlIndexSubEntry.get('display') is not None:
strIndexHtml = strIndexHtml + "<p>" + xmlIndexSubEntry.get('display') + "<br/>"
else:
strIndexHtml = strIndexHtml + "<p>" + xmlIndexSubEntry.get('secondary') + "<br/>"
intSubIndexLinkNumber = 1
for xmlIndexSublink in xmlIndexSubEntry.findall("EOAindexlink"):
strIndexSubLink = "<a href=\"/" + Newpublication.Serie.lower() + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlIndexSublink.get('chapterorder') + "/index.html#" + xmlIndexSublink.get('elementorder') + "\">"
strIndexSubLink = strIndexSubLink + str(intSubIndexLinkNumber) + "</a> "
if xmlIndexSublink.get("bold") == "True":
strIndexSubLink = "<b>" + strIndexSubLink + "</b>"
strIndexHtml = strIndexHtml + strIndexSubLink
intSubIndexLinkNumber += 1
strIndexHtml = strIndexHtml + "</p>"
# Die Divs schliessen
strIndexHtml = strIndexHtml + "</div></div></div>"
intIndexEntry += 1
strResult += strIndexHtml
strResult = strResult + "</div>"
Newindexsection.Html = strResult
Newindexsection.save()
xmlIndex = xmlTree.find(".//EOAprintpersonindex")
if xmlIndex is not None:
xmlIndexsections = xmlIndex.findall(".//EOAindexsection")
intObjectOrder = 1
intIndexEntry = 1
for xmlIndexsection in xmlIndexsections:
Newindexsection = Indexsection(Publication=Newpublication)
Newindexsection.Kind = 'person'
Newindexsection.Title = xmlIndexsection.get("Character")
Newindexsection.Order = intObjectOrder
intObjectOrder += 1
strResult = "<div class=\"accordion\" id=\"accordion" + str(intObjectOrder) + "\">"
for xmlIndexEntry in xmlIndexsection.iterchildren():
strIndexHtml = """<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion"""
strIndexHtml = strIndexHtml + str(intIndexEntry) + "\" href=\"#" + "indexentry" + str(intIndexEntry) + "\">"
if xmlIndexEntry.get('display') is not None:
strIndexHtml = strIndexHtml + unicode(xmlIndexEntry.get('display'))
else:
strIndexHtml = strIndexHtml + str(xmlIndexEntry.get('main'))
strIndexHtml = strIndexHtml + """</a></div> <div id="""
strIndexHtml = strIndexHtml + "\"indexentry" + str(intIndexEntry) + "\""
strIndexHtml = strIndexHtml + """ class="accordion-body collapse"><div class="accordion-inner">"""
# Process Links of the main entry
intMainIndexLinkNumber = 1
for xmlIndexlink in xmlIndexEntry.findall("./EOAindexlink"):
strIndexLink = "<a href=\"/" + Newpublication.Serie.lower() + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlIndexlink.get('chapterorder') + "/index.html#" + xmlIndexlink.get('elementorder') + "\">"
strIndexLink = strIndexLink + str(intMainIndexLinkNumber) + "</a> "
if xmlIndexlink.get('bold') == "True":
strIndexLink = "<strong>" + strIndexLink + "</strong>"
strIndexHtml = strIndexHtml + strIndexLink
intMainIndexLinkNumber += 1
# Process Subentries if available
for xmlIndexSubEntry in xmlIndexEntry.findall(".//EOAindexsubentry"):
if xmlIndexSubEntry.get('display') is not None:
strIndexHtml = strIndexHtml + "<p>" + xmlIndexSubEntry.get('display') + "<br/>"
else:
strIndexHtml = strIndexHtml + "<p>" + xmlIndexSubEntry.get('secondary') + "<br/>"
intSubIndexLinkNumber = 1
for xmlIndexSublink in xmlIndexSubEntry.findall("EOAindexlink"):
strIndexSubLink = "<a href=\"/" + Newpublication.Serie.lower() + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlIndexSublink.get('chapterorder') + "/index.html#" + xmlIndexSublink.get('elementorder') + "\">"
strIndexSubLink = strIndexSubLink + str(intSubIndexLinkNumber) + "</a> "
if xmlIndexSublink.get("bold") == "True":
strIndexSubLink = "<b>" + strIndexSubLink + "</b>"
strIndexHtml = strIndexHtml + strIndexSubLink
intSubIndexLinkNumber += 1
strIndexHtml = strIndexHtml + "</p>"
# Die Divs schliessen
strIndexHtml = strIndexHtml + "</div></div></div>"
intIndexEntry += 1
strResult += strIndexHtml
strResult = strResult + "</div>"
Newindexsection.Html = strResult
Newindexsection.save()
xmlIndex = xmlTree.find(".//EOAprintlocationindex")
if xmlIndex is not None:
xmlIndexsections = xmlIndex.findall(".//EOAindexsection")
intObjectOrder = 1
intIndexEntry = 1
for xmlIndexsection in xmlIndexsections:
Newindexsection = Indexsection(Publication=Newpublication)
Newindexsection.Kind = 'location'
Newindexsection.Title = xmlIndexsection.get("Character")
Newindexsection.Order = intObjectOrder
intObjectOrder += 1
strResult = "<div class=\"accordion\" id=\"accordion" + str(intObjectOrder) + "\">"
for xmlIndexEntry in xmlIndexsection.iterchildren():
strIndexHtml = """<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion"""
strIndexHtml = strIndexHtml + str(intIndexEntry) + "\" href=\"#" + "indexentry" + str(intIndexEntry) + "\">"
if xmlIndexEntry.get('display') is not None:
strIndexHtml = strIndexHtml + unicode(xmlIndexEntry.get('display'))
else:
strIndexHtml = strIndexHtml + str(xmlIndexEntry.get('main'))
strIndexHtml = strIndexHtml + """</a></div> <div id="""
strIndexHtml = strIndexHtml + "\"indexentry" + str(intIndexEntry) + "\""
strIndexHtml = strIndexHtml + """ class="accordion-body collapse"><div class="accordion-inner">"""
# Process Links of the main entry
intMainIndexLinkNumber = 1
for xmlIndexlink in xmlIndexEntry.findall("./EOAindexlink"):
strIndexLink = "<a href=\"/" + Newpublication.Serie.lower() + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlIndexlink.get('chapterorder') + "/index.html#" + xmlIndexlink.get('elementorder') + "\">"
strIndexLink = strIndexLink + str(intMainIndexLinkNumber) + "</a> "
if xmlIndexlink.get('bold') == "True":
strIndexLink = "<strong>" + strIndexLink + "</strong>"
strIndexHtml = strIndexHtml + strIndexLink
intMainIndexLinkNumber += 1
# Process Subentries if available
for xmlIndexSubEntry in xmlIndexEntry.findall(".//EOAindexsubentry"):
if xmlIndexSubEntry.get('display') is not None:
strIndexHtml = strIndexHtml + "<p>" + xmlIndexSubEntry.get('display') + "<br/>"
else:
strIndexHtml = strIndexHtml + "<p>" + xmlIndexSubEntry.get('secondary') + "<br/>"
intSubIndexLinkNumber = 1
for xmlIndexSublink in xmlIndexSubEntry.findall("EOAindexlink"):
strIndexSubLink = "<a href=\"/" + Newpublication.Serie.lower() + \
"/"+ cfgPublication.get('Technical', 'Number') \
+ "/" + xmlIndexSublink.get('chapterorder') + "/index.html#" + xmlIndexSublink.get('elementorder') + "\">"
strIndexSubLink = strIndexSubLink + str(intSubIndexLinkNumber) + "</a> "
if xmlIndexSublink.get("bold") == "True":
strIndexSubLink = "<b>" + strIndexSubLink + "</b>"
strIndexHtml = strIndexHtml + strIndexSubLink
intSubIndexLinkNumber += 1
strIndexHtml = strIndexHtml + "</p>"
# Die Divs schliessen
strIndexHtml = strIndexHtml + "</div></div></div>"
intIndexEntry += 1
strResult += strIndexHtml
strResult = strResult + "</div>"
Newindexsection.Html = strResult
Newindexsection.save()
shutil.copytree(strDir, import_files_dir)
print("Import finished")
# class Command ends here