Commit ab51b756 authored by mitshel's avatar mitshel
Browse files

Development sopdswrap.py, sopdstempl.py modules, Intermediate commit.

parent 3de7bcdc
Loading
Loading
Loading
Loading
+55 −53
Original line number Diff line number Diff line
@@ -45,25 +45,6 @@ def websym(s,attr=False):
        result = result.replace(k,table[k])
    return result;

def opensearch(script):
    code='''<?xml version="1.0" encoding="utf-8"?>
            <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
            <ShortName>SimpleOPDS</ShortName>
            <LongName>SimpleOPDS</LongName>
            <Url type="application/atom+xml" template="{0}?searchTerm={{searchTerms}}" />
            <Image width="16" height="16">http://www.sopds.ru/favicon.ico</Image>
            <Tags />
            <Contact />
            <Developer />
            <Attribution />
            <SyndicationRight>open</SyndicationRight>
            <AdultContent>false</AdultContent>
            <Language>*</Language>
            <OutputEncoding>UTF-8</OutputEncoding>
            <InputEncoding>UTF-8</InputEncoding>
            </OpenSearchDescription>'''.format(script)
    return code

#######################################################################
#
# Основной класс OPDS-клиента
@@ -205,6 +186,12 @@ class opdsClient():
    def authors_submenu(self,author_id):
        self.Wrapper.authors_submenu(author_id)

    def opensearch_links(self,page_data):
        self.Wrapper.opensearch_links(page_data)

    def opensearch_forms(self,page_data):
        self.Wrapper.opensearch_forms(page_data)

    def get_authors(self,book_id):
        return self.Wrapper.get_authors(self.opdsdb.getauthors(book_id))

@@ -220,18 +207,30 @@ class opdsClient():
    def entry_navigation(self,nav_data):
        self.Wrapper.entry_navigation(nav_data)

    def page_control(self, page, link_id):
        if page>0:
           self.Wrapper.page_control_prev(page,link_id)
    def page_control(self, page_data):
        data=page_data.copy()
        data['link_id']=self.id_value
        data['page']=self.page_value
        if self.page_value>0:
           data['page_prev']=self.page_value-1
        else:
           data['page_prev']=-1
        if self.opdsdb.next_page:
           self.Wrapper.page_control_next(page,link_id)
           data['page_next']=self.page_value+1
        else:
           data['page_next']=-1;
        self.Wrapper.page_control(data)

    def alphabet_menu(self,iid_value):
        self.Wrapper.alphabet_menu(iid_value,self.nl) 

    def response_search(self):
        self.Wrapper.opensearch()

    def response_main(self):
        page_data={'page_id':'id:main', 'page_title':'SOPDS|Главная', 'page_updated':time.strftime("%Y-%m-%dT%H:%M:%SZ")}
        self.header(page_data)
        self.opensearch_links(page_data)
        self.main_menu()
        self.footer(page_data)

@@ -255,7 +254,7 @@ class opdsClient():
                         'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                         'nl':self.nl, 'dcount':0}
               self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer()

    def response_alpha(self):
@@ -359,7 +358,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl, 'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_doubles(self):
@@ -376,7 +375,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl,'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)


@@ -417,7 +416,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl, 'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_last(self):
@@ -427,27 +426,34 @@ class opdsClient():
        self.new_menu()
        self.footer(page_data)

    def response_search_type(self):
        """ Выбор типа поиска по автору или наименованию или серии """
        page_data={'page_id':'id:search:%s'%self.searchTerm,'page_title':'Поиск %s'%self.searchTerm, 'page_updated':time.strftime("%Y-%m-%dT%H:%M:%SZ")}
        self.header(page_data)
        self.add_response_body('<link href="'+self.modulePath+'?id=09" rel="search" type="application/opensearchdescription+xml" />')
        self.add_response_body('<link href="'+self.modulePath+'?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />')
#    def response_search_type(self):
#        """ Выбор типа поиска по автору или наименованию или серии """
#        page_data={'page_id':'id:search:%s'%self.searchTerm,'page_title':'Поиск %s'%self.searchTerm, 'page_updated':time.strftime("%Y-%m-%dT%H:%M:%SZ")}
#        self.header(page_data)
#        self.add_response_body('<link href="'+self.modulePath+'?id=09" rel="search" type="application/opensearchdescription+xml" />')
#        self.add_response_body('<link href="'+self.modulePath+'?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />')
#        self.entry_start()
        self.entry_head('Поиск книг',None,'71')
        self.entry_content('Поиск книги по ее наименованию')
        self.add_response_body('<link type="application/atom+xml;profile=opds-catalog" href="'+self.modulePath+'?searchType=books&amp;searchTerm='+parse.quote(self.searchTerm)+'" />')
#        self.entry_head('Поиск книг',None,'71')
#        self.entry_content('Поиск книги по ее наименованию')
#        self.add_response_body('<link type="application/atom+xml;profile=opds-catalog" href="'+self.modulePath+'?searchType=books&amp;searchTerm='+parse.quote(self.searchTerm)+'" />')
#        self.entry_finish()
#        self.entry_start()
        self.entry_head('Поиск авторов',None,'72')
        self.entry_content('Поиск авторов по имени')
        self.add_response_body('<link type="application/atom+xml;profile=opds-catalog" href="'+self.modulePath+'?searchType=authors&amp;searchTerm='+parse.quote(self.searchTerm)+'" />')
#        self.entry_head('Поиск авторов',None,'72')
#        self.entry_content('Поиск авторов по имени')
#        self.add_response_body('<link type="application/atom+xml;profile=opds-catalog" href="'+self.modulePath+'?searchType=authors&amp;searchTerm='+parse.quote(self.searchTerm)+'" />')
#        self.entry_finish()
#        self.entry_start()
        self.entry_head('Поиск серий',None,'73')
        self.entry_content('Поиск серий книг')
        self.add_response_body('<link type="application/atom+xml;profile=opds-catalog" href="'+self.modulePath+'?searchType=series&amp;searchTerm='+parse.quote(self.searchTerm)+'" />')
#        self.entry_head('Поиск серий',None,'73')
#        self.entry_content('Поиск серий книг')
#        self.add_response_body('<link type="application/atom+xml;profile=opds-catalog" href="'+self.modulePath+'?searchType=series&amp;searchTerm='+parse.quote(self.searchTerm)+'" />')
#        self.entry_finish()
#        self.footer(page_data)

    def response_search_type(self):
        page_data={'page_id':'id:search:%s'%self.searchTerm,'page_title':'Поиск %s'%self.searchTerm, 'page_updated':time.strftime("%Y-%m-%dT%H:%M:%SZ"),'searchterm':parse.quote(self.searchTerm)}
        self.header(page_data)
        self.opensearch_links(page_data)
        self.opensearch_forms(page_data)
        self.footer(page_data)

    def response_bookshelf(self):
@@ -464,7 +470,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl, 'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_authors_search(self):
@@ -485,7 +491,7 @@ class opdsClient():
            nav_data={'link_id':id,'e_date':None,'e_title':(last_name+' '+first_name),'e_id':'author:%s'%(author_id),'e_nav_info':('Всего: '+str(cnt)+' книг.'),
                      'nl':self.nl}
            self.entry_navigation(nav_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_series_search(self):
@@ -506,7 +512,7 @@ class opdsClient():
            nav_data={'link_id':id,'e_date':None,'e_title':ser,'e_id':'series:%s'%(ser_id),'e_nav_info':('Всего: '+str(cnt)+' книг.'),
                      'nl':self.nl}
            self.entry_navigation(nav_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_authors_submenu(self):
@@ -527,7 +533,7 @@ class opdsClient():
            nav_data={'link_id':id,'e_date':None,'e_title':ser,'e_id':'series:%s'%(ser_id),'e_nav_info':('Всего: '+str(cnt)+' книг.'),
                      'nl':self.nl}
            self.entry_navigation(nav_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_authors_alpha(self):
@@ -545,7 +551,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl, 'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_authors_series_books(self):
@@ -563,7 +569,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl, 'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_series_books(self):
@@ -581,7 +587,7 @@ class opdsClient():
                      'authors':authors,'genres':genres,'series':series,'authors_link':authors_link,'genres_link':genres_link, 'series_link':series_link,
                      'nl':self.nl, 'dcount':self.opdsdb.getdoublecount(book_id)}
            self.entry_acquisition(acq_data)
        self.page_control(self.page_value,self.id_value)
        self.page_control(page_data)
        self.footer(page_data)

    def response_book_file(self):
@@ -748,10 +754,6 @@ class opdsClient():
           else:
              self.set_response_status('404 Not Found')

    def response_search(self):
        self.add_response_header([('Content-Type','text/xml')])
        self.add_response_body(opensearch(self.modulePath))

    def make_response(self):
        self.opdsdb.openDB()

+11 −3
Original line number Diff line number Diff line
@@ -78,14 +78,14 @@ class fb2cover(fb2tag):
   def __init__(self,tags):
       self.iscover=False
       self.cover_name=''
       self.cover_data=''
       self._cover_data=[]
       self.isfind=False
       fb2tag.__init__(self,tags)

   def reset(self):
       self.iscover=False
       self.cover_name=''
       self.cover_data=''
       self._cover_data=[]
       self.isfind=False
       fb2tag.reset(self)

@@ -113,7 +113,15 @@ class fb2cover(fb2tag):
   def add_data(self,data):
       if self.iscover:
          if data!='\\n':
             self.cover_data+=data
             self._cover_data.append(data)

   @property
   def cover_data(self):
       return ''.join(self._cover_data)

   @cover_data.setter
   def cover_data(self, value):
       self._cover_data = [value]

class fb2parser:
   def __init__(self, readcover=0):
+48 −27
Original line number Diff line number Diff line
class opdsTemplate():
    def __init__(self,charset='utf-8'):
       self.response_header=('Content-Type','text/xml; charset='+charset)
       self.opensearch=('<?xml version="1.0" encoding="utf-8"?>'
                        '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">'
                        '<ShortName>SimpleOPDS</ShortName>'
                        '<LongName>SimpleOPDS</LongName>'
                        '<Url type="application/atom+xml" template="%(modulepath)s?searchTerm={searchTerms}" />'
                        '<Image width="16" height="16">http://www.sopds.ru/favicon.ico</Image>'
                        '<Tags />'
                        '<Contact />'
                        '<Developer />'
                        '<Attribution />'
                        '<SyndicationRight>open</SyndicationRight>'
                        '<AdultContent>false</AdultContent>'
                        '<Language>*</Language>'
                        '<OutputEncoding>UTF-8</OutputEncoding>'
                        '<InputEncoding>UTF-8</InputEncoding>'
                        '</OpenSearchDescription>')
       self.opensearch_links=('<link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" />'
                              '<link href="%(modulepath)s?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />')   
       self.opensearch_forms=('<entry><title>Поиск книг</title><id>id:search:71</id><content type="text">Поиск книги по ее наименованию</content>'
                              '<link type="application/atom+xml;profile=opds-catalog" href="%(modulepath)s?searchType=books&amp;searchTerm=%(searchterm)s" />'
                              '</entry>'
                              '<entry><title>Поиск авторов</title><id>id:search:72</id><content type="text">Поиск авторов по имени</content>'
                              '<link type="application/atom+xml;profile=opds-catalog" href="%(modulepath)s?searchType=authors&amp;searchTerm=%(searchterm)s" />'
                              '</entry>'
                              '<entry><title>Поиск серий</title><id>id:search:73</id><content type="text">Поиск серий книг</content>'
                              '<link type="application/atom+xml;profile=opds-catalog" href="%(modulepath)s?searchType=series&amp;searchTerm=%(searchterm)s" />'
                              '</entry>')

       self.agregate_authors=('<author><name>%(last_name)s %(first_name)s</name></author>')
       self.agregate_authors_link=('<link href="%(modulepath)s?id=22%(author_id)s" rel="related" type="application/atom+xml;profile=opds-catalog" title="Все книги %(last_name)s %(first_name)s" />')
@@ -20,8 +47,7 @@ class opdsTemplate():
                               '<author><name>%(site_author)s</name><uri>%(site_url)s</uri><email>%(site_email)s</email></author>'
                               '<link type="application/atom+xml" rel="start" href="%(modulepath)s?id=00"/>')
       self.document_page_footer='</feed>'
       self.document_mainmenu_std=('<link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" />'
                               '<link href="%(modulepath)s?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />'
       self.document_mainmenu_std=(
                               '<entry>'
                               '<title>По каталогам</title>'
                               '<content type="text">Каталогов: %(cat_num)s, книг: %(book_num)s.</content>'
@@ -97,11 +123,12 @@ class opdsTemplate():
                                    '<entry><title>Другие Символы</title><id>alpha:4</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%(iid)s&amp;alpha=4%(nl)s"/></entry>'
                                    '<entry><title>Показать все</title><id>alpha:5</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%(iid)s&amp;alpha=5%(nl)s"/></entry>'
                                    )

       self.document_page_control_prev=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="prev" title="Previous Page" href="%(modulepath)s?id=%%(link_id)s&amp;page=%(page)s" />'
       self.document_page_control_start=''
       self.document_page_control_prev=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="prev" title="Previous Page" href="%(modulepath)s?id=%(link_id)s&amp;page=%(page_prev)s" />'
                               )
       self.document_page_control_next=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="next" title="Next Page" href="%(modulepath)s?id=%%(link_id)s&amp;page=%(page)s" />'
       self.document_page_control_next=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="next" title="Next Page" href="%(modulepath)s?id=%(link_id)s&amp;page=%(page_next)s" />'
                               )
       self.document_page_control_finish=''

       self.document_entry_nav_start='<entry>'
       self.document_entry_nav_title=('<title>%(e_title)s</title>'
@@ -164,6 +191,10 @@ class webTemplate(opdsTemplate):
#
# 


       self.opensearch=''
       self.opensearch_links=''
       self.opensearch_forms=''
       self.agregate_authors=('%(last_name)s %(first_name)s, ')
       self.agregate_authors_link=('<a href="%(modulepath)s?id=22%(author_id)s">%(last_name)s %(first_name)s, </a>'
                               )
@@ -176,14 +207,14 @@ class webTemplate(opdsTemplate):

       self.document_page_header_style='''
                           <style>
                               body {font-family: Tahoma, Geneva, sans-serif; font-size: 8pt; color: #000; margin: 0; padding: 20px 20px 20px 20px; }
                               h1 {font-size: 140%%; margin-bottom: 30px; }
                               body {font-family: Tahoma, Geneva, sans-serif; font-size: 8pt; color: #000; }
                               h1 {font-size: 130%%; margin-bottom: 10px; }
                               h2 {font-size: 120%%; }
                               h2 a { color: #000; }
                               a {color: #0F3253;}
                               .page { padding: 5px 5px 5px 5px; }
                               .header {padding-top: 0pt; border-bottom: 2pt dotted #AAA; margin-top: 0pt; line-height=10pt; }
                               .footer {padding-top: 0pt; border-top: 2pt dotted #AAA; margin-top: 0pt; }
                               .footer {padding-top: 10pt; border-top: 2pt dotted #AAA; margin-top: 0pt; }
                               .navigation_entry  { padding: 0 20px 0 20px; line-height:0; }
                               .navigation_entry h2 { display: inline-block; }
                               .acquisition_entry { padding: 0 20px 0 20px; }
@@ -194,6 +225,7 @@ class webTemplate(opdsTemplate):
                               .acq_annotation { font-size: 90%%; }
                               .acq_info_container { clear: both; }
                               .acq_rel { clear: both; }
                               .page_control { text-align:center; }
                            </style>
                            '''
       self.document_page_header=('<html>'
@@ -216,23 +248,10 @@ class webTemplate(opdsTemplate):
                               )
       self.document_mainmenu_shelf=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=08">Книжная полка для %(user)s.</a></h2><i></i></div>'
                               )
       self.document_newmenu=('<entry>'
                               '<title>Все новинки за %(new_period)s суток</title>'
                               '<content type="text">Новых книг: %(newbook_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%(alphabet_id)s03&amp;news=1"/>'
                               '<id>id:03:news</id></entry>'
                               '<entry>'
                               '<title>Новинки по авторам</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%(alphabet_id)s02&amp;news=1"/>'
                               '<id>id:02:news</id></entry>'
                               '<entry>'
                               '<title>Новинки по Жанрам</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=04&amp;news=1"/>'
                               '<id>id:04:news</id></entry>'
                               '<entry>'
                               '<title>Новинки по Сериям</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%(alphabet_id)s06&amp;news=1"/>'
                               '<id>id:06:news</id></entry>'
       self.document_newmenu=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=%(alphabet_id)s03&amp;news=1">Все новинки за %(new_period)s суток</a></h2></div>'
                              '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%(alphabet_id)s02&amp;news=1">Новинки по авторам</a></h2></div>'
                              '<div class=navigation_entry><h2><a href="%(modulepath)s?id=04&amp;news=1">Новинки по Жанрам</a></h2></div>'
                              '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%(alphabet_id)s02&amp;news=1">Новинки по Сериям</a></h2></div>'
                               )
       self.document_authors_submenu=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=31%(author_id)s">Книги по сериям</a></h2><i></i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=34%(author_id)s">Книги вне серий</a></h2><i></i></div>'
@@ -245,11 +264,13 @@ class webTemplate(opdsTemplate):
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%(iid)s&amp;alpha=4%(nl)s">Другие символы</a></h2><i></i></div>'
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%(iid)s&amp;alpha=5%(nl)s">Показать все</a></h2><i></i></div>'
                                    )
       self.document_page_control_start='<div class=page_control>'

       self.document_page_control_prev=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="prev" title="Previous Page" href="%(modulepath)s?id=%(link_id)s&amp;page=%(page)s" />'
       self.document_page_control_prev=('&nbsp;<a href="%(modulepath)s?id=%(link_id)s&amp;page=%(page_prev)s">&lt;Предыдущая страница </a>'
                               )
       self.document_page_control_next=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="next" title="Next Page" href="%(modulepath)s?id=%(link_id)s&amp;page=%(page)s" />'
       self.document_page_control_next=('&nbsp;<a href="%(modulepath)s?id=%(link_id)s&amp;page=%(page_next)s">Следующая страница&gt;'
                               )
       self.document_page_control_finish='</div>'

###############################################################################################################################
#
+18 −5

File changed.

Preview size limit exceeded, changes collapsed.