예제 #1
0
 def get_idevice_el(self, idevice_type):
     """Returns a tuple with the directory which contains the idevice and it's etree element parsed"""
     from exe.engine.epubpackage import EPUBPackage
     idevice_dir = EPUBPackage.find_idevice_dir(idevice_type)
     
     if idevice_dir:
         root_el = etree.parse(idevice_dir/"idevice.xml").getroot()
         return (idevice_dir, root_el)
     else:
         return (None, None)
예제 #2
0
 def add_required_files_to_package(self, required_files):
     for file in required_files:
         src_path = None
                     
         if file[:len(EPUBResourceManager.PREFIX_COMMON_FILES)] == EPUBResourceManager.PREFIX_COMMON_FILES:
             rel_path = file[len(EPUBResourceManager.PREFIX_COMMON_FILES)+1:]
             src_path = os.path.join(G.application.config.webDir, "templates", rel_path)
         elif file[:len(EPUBResourceManager.PREFIX_IDEVICE_FILES)] == EPUBResourceManager.PREFIX_IDEVICE_FILES:
             idevice_trimmed = file[len(EPUBResourceManager.PREFIX_IDEVICE_FILES)+1:]
             sep_index = idevice_trimmed.index('/')
             idevice_type = idevice_trimmed[:sep_index]
             rel_path = idevice_trimmed[sep_index+1:]
             
             from exe.engine.epubpackage import EPUBPackage
             src_path = os.path.join(EPUBPackage.find_idevice_dir(idevice_type), rel_path)
             
         self.opf.add_file(src_path, file, auto_update = True)
예제 #3
0
 def render_POST(self, request=None):
     idevices = json.loads(request.args['idevices'][0])
     if isinstance(idevices, dict):
         idevices = [idevices]
         
     if isinstance(self.package, EPUBPackage):
         for idevice in idevices:
             idevice_dir = EPUBPackage.find_idevice_dir(idevice['id'])
             idevice_xml_path = os.path.join(idevice_dir, "idevice.xml")
             idevice_xml = etree.parse(idevice_xml_path)
             ns = idevice_xml.getroot().nsmap.get(None)
             visible_str = ""
             if idevice['visible']:
                 visible_str = "true"
             else:
                 visible_str = "false"
             
             visible_el = idevice_xml.getroot().find(".//{%s}visible" % ns)
             visible_el.text = visible_str
              
             idevice_fd = open(idevice_xml_path, "w")
             idevice_fd.write(etree.tostring(idevice_xml.getroot(), encoding = "UTF-8", pretty_print = True))
             idevice_fd.flush()
             idevice_fd.close()
             
     else:
         for idevice in idevices:
             prototype = self.prototypes[idevice['id']]
             visible = idevice['visible']
             lower_title = prototype._title.lower()
             try:
                 self.config.hiddeniDevices.remove(lower_title)
                 self.config.configParser.delete('idevices', lower_title)
             except:
                 pass
             if not visible:
                 self.config.hiddeniDevices.append(lower_title)
                 self.config.configParser.set('idevices', lower_title, '0')
                 
     return json.dumps({'success': True})