Beispiel #1
0
 def set_not_found(self):
     ''' - This is actually not needed since 'self.delete_head' will
           remove the entire article if it consists of comments only.
           We keep this code just to be on a safe side (e.g., in case
           the author of MT adds non-comment blocks).
         - Takes ~0.007s for 'set' (EN-RU) on AMD E-300
     '''
     f = '[MClient] plugins.multitrancom.elems.Elems.set_not_found'
     texts = [block.text for block in self.blocks]
     ru = ('Forvo', '|', '+', '\xa0Не найдено')
     en = ('Forvo', '|', '+', '\xa0Not found')
     if sh.List(texts, ru).find() or sh.List(texts, en).find():
         sh.com.rep_deleted(f, len(self.blocks))
         self.blocks = []
     else:
         sh.com.rep_lazy(f)
Beispiel #2
0
 def run(self):
     ''' - We should unite items in 'fixed+comment (SAME=1)'
           structures directly since fixed columns having
           supplementary SAME=1 blocks cannot be properly sorted.
         - Running the entire class takes ~0.0131s for 'set' (EN-RU)
           on AMD E-300
     '''
     f = '[MClient] plugins.multitrancom.elems.UniteFixed.run'
     count = 0
     self.set_cells()
     for i in range(len(self.cells)):
         types = [block.type_ for block in self.cells[i]]
         if self.has_two_fixed(types):
             count += len(self.cells[i])
             self.cells[i][0].type_ = self.get_first_fixed_type(
                 self.cells[i])
             texts = [block.text for block in self.cells[i] \
                      if block.text
                     ]
             self.cells[i][0].text = sh.List(texts).space_items()
             self.cells[i] = [self.cells[i][0]]
     self.blocks = []
     for cell in self.cells:
         self.blocks += cell
     sh.com.rep_matches(f, count)
     return self.blocks
Beispiel #3
0
 def delete_tail_links(self):
     ''' - Sometimes it's not enough to delete comment-only tail
           since there might be no 'phdic' type which serves as
           an indicator.
         - Takes ~0.02s for 'set' (EN-RU) on Intel Atom
     '''
     ru = ('Добавить', '|', 'Сообщить об ошибке', '|',
           'Ссылка на эту страницу', '|', 'Способы выбора языков')
     en = ('Add', '|', 'Report an error', '|', 'Get short URL', '|',
           'Language Selection Tips')
     de = ('Hinzufügen', '|', 'Fehlerhaften Eintrag melden', '|',
           'Get short URL', '|', 'Hinweise')
     sp = ('Añadir', '|', 'Enviar un mensaje de error', '|',
           'Enlace corto a esta página', '|',
           'Modos de seleccionar idiomas')
     uk = ('Додати', '|', 'Повідомити про помилку', '|',
           'Посилання на цю сторінку', '|', 'Способи вибору мов')
     texts = [block.text for block in self.blocks]
     self._delete_tail_links(sh.List(texts, ru).find())
     self._delete_tail_links(sh.List(texts, en).find())
     self._delete_tail_links(sh.List(texts, de).find())
     self._delete_tail_links(sh.List(texts, sp).find())
     self._delete_tail_links(sh.List(texts, uk).find())
     ru = ('Добавить', '|', 'Способы выбора языков')
     en = ('Add', '|', 'Language Selection Tips')
     self._delete_tail_links(sh.List(texts, ru).find())
     self._delete_tail_links(sh.List(texts, en).find())
Beispiel #4
0
 def __init__ (self,product='MClient'
              ,version='current'
              ):
     self.set_values()
     self.product = product
     self.version = version
     self.desc = sh.List (lst1 = [self.product
                                 ,self.version
                                 ]
                         ).space_items()
Beispiel #5
0
 def unite_comments(self):
     i = 0
     while i < len(self.blocks):
         if self.blocks[i].type_ == 'comment' \
         and self.blocks[i].same > 0:
             if i > 0 and self.blocks[i - 1].type_ == 'comment':
                 self.blocks[i-1].text \
                         = sh.List (lst1 = [self.blocks[i-1].text
                                   ,self.blocks[i].text
                                   ]
                                   ).space_items()
                 del self.blocks[i]
                 i -= 1
         i += 1
Beispiel #6
0
 def request(self,search='',url=''):
     f = '[MClient] plugins.dsl.run.Plugin.request'
     self.blocks = []
     htm = []
     self.search = search
     articles = gt.Get(search).run()
     for iarticle in articles:
         htm.append(iarticle.code)
         code = cu.CleanUp(iarticle.code).run()
         code = cu.TagLike(code).run()
         self.blocks += tg.Tags (code = code
                                ,Debug = self.Debug
                                ,maxrows = self.maxrows
                                ,dicname = iarticle.dic
                                ).run()
     self.htm = '\n'.join(htm)
     texts = [block.text for block in self.blocks if block.text]
     self.text = sh.List(texts).space_items()
     self.blocks = el.Elems (blocks = self.blocks
                            ,Debug = self.Debug
                            ).run()
     return self.blocks
Beispiel #7
0
 def _get_cuts1(self):
     f = '[MClient] subjects.priorities.controller.Priorities._get_cuts1'
     indexes = self.get_gui().get_index_mult1()
     if indexes:
         cutsi = sh.List(indexes).split_by_gaps()
         if cutsi:
             cuts = []
             for cuti in cutsi:
                 cut = []
                 for index_ in cuti:
                     cut.append(self.lst1[index_])
                 cuts.append(cut)
             cutsi = cutsi[::-1]
             for cuti in cutsi:
                 cuti = cuti[::-1]
                 for i in cuti:
                     del self.lst1[i]
             cutsi = cutsi[::-1]
             return(cuts,cutsi)
         else:
             sh.com.rep_empty(f)
     else:
         sh.com.rep_lazy(f)
Beispiel #8
0
 def get_separate_head(self):
     blocks = ('Forvo', '|', '+')
     texts = [block.text for block in self.blocks]
     return sh.List(texts, blocks).find()
Beispiel #9
0
 def set_gui(self):
     self.parent = sh.Top(icon=ICON,
                          title=sh.List([PRODUCT, VERSION]).space_items())
     self.set_buttons()
     self.set_bindings()