示例#1
0
 def lock(self, lock_slug):
     lock_filename = self.lock_filename(lock_slug)
     if exists(lock_filename):
         raise StorageError(f"Can't lock: Storage is already locked: "
                            f'"{lock_filename}"')
     write(lock_filename, dt())
     self.locked = True
示例#2
0
 def _all(self, limit=None):
     iterator = storage.iterate_pages(silent=True, limit=limit)
     for i, (title, page) in enumerate(iterator):
         self._debug_title(i, title)
         if not i % 100000:
             print(dt(), i)
         self.update_page(page)
     self.convert_entries()
     self.export_entries('.current')
示例#3
0
    def update_page(self, title, content, edited, redirect):
        old_content, old_info = self.storage.get(title, silent=True)

        edited_str = dt(edited, utc=True)
        info = f"{edited_str}, {'R' if redirect else 'A'}"

        if content != old_content or info != old_info:
            self.storage.update(title, content=content, info=info)
            self.log_hour('changed', f'<{info}> - {title}')
            self.log_day('titles_changed', title)
示例#4
0
 def wrapped(*args, **kwargs):
     lock_file = join(conf.root_path, 'sys', 'lock', slug)
     if exists(lock_file):
         print(dt(), f'Already locked: `{slug}`')
         return
     write(lock_file, '')
     try:
         return func(*args, **kwargs)
     finally:
         os.remove(lock_file)
示例#5
0
 def lock(self, lock_slug):
     lock_filename = self.lock_filename(lock_slug)
     if exists(lock_filename):
         storages = {
             '/home/vitalik/storages/wiktionary/storage'
             '/authors/sys/lock_recent':
             '*authors*',
         }
         storage_name = storages.get(lock_filename, lock_filename)
         post_to_slack(
             'recent-errors', f':lock: `{Logger.slug}` '
             f'Storage is locked: {storage_name}')
         raise StorageAlreadyLocked(
             f'Can\'t lock: Storage is already locked: "{lock_filename}"')
     write(lock_filename, dt())
     self.locked = True
示例#6
0
    def update_page(self, page):  # todo: rename to `update_page`
        title = page.title
        if title in self.storage.titles_set:
            # Информация об авторе этой статьи уже сохранена
            self._debug_skipped()
            return False

        # get oldest revision
        oldest = next(
            get_page(title).revisions(reverseOrder=True, total=1,
                                      content=True))
        created_at = dt(oldest.timestamp, utc=True)
        created_lang = self.get_created_lang(title, oldest.text)
        created_author = oldest.user
        created = f"{created_at}, {created_lang}, {created_author}"
        self._debug_info(created)

        self.storage.update(title, created=created)
        self.log_hour('saved', f'<{created}> - {title}')
        self.log_day('titles_saved', title)
        self._debug_processed()
        return True
示例#7
0
文件: io.py 项目: soshial/wiktionary
def lock_file(
    filename
):  # todo: возможно попробовать сделать context manager `with locked(...):`
    if is_locked(filename):
        raise LockError(filename)
    write(filename + b'.lock', dt())
示例#8
0
 def update_page(self, title, content, edited, redirect):
     edited_str = dt(edited, utc=True)
     info = f"{edited_str}, {'R' if redirect else 'A'}"
     self.storage.update(title, content=content, info=info)
     self.log_hour('changed', f'<{info}> - {title}')
     self.log_day('titles_changed', title)
示例#9
0
 def _debug_title(self, title):
     print(dt(), title)
示例#10
0
 def latest_updated(self, value):
     write(self.latest_updated_filename, dt(value, utc=True))
示例#11
0
 def _debug_title(self, i, title):
     print(dt(), i, title, ' --  ', end='')
示例#12
0
 def _debug_titles_saved(self):
     print(dt(), '## Titles saved!')