def cp_chksum_tmpfiles_to_permfile(self): if Checksummer.NAME in self._enabled: for htype in Checksummer.HASHTYPES: tmp_filename = self._get_checksum_filename_tmp(htype) real_filename = self._get_checksum_filename(htype) text = FileUtils.read_file(tmp_filename) FileUtils.write_file(self.wiki.config.temp_dir, real_filename, text, self.wiki.config.fileperms)
def cp_chksum_tmpfiles_to_permfile(self): """ during a dump run, checksum files are written to a temporary location and updated there; we copy the content from these files into the permanent location after each dump job completes """ if Checksummer.NAME in self._enabled: for htype in Checksummer.HASHTYPES: for fmt in Checksummer.FORMATS: tmp_filename = self._get_checksum_filename_tmp(htype, fmt) real_filename = self._get_checksum_path(htype, fmt) content = FileUtils.read_file(tmp_filename) FileUtils.write_file( FileUtils.wiki_tempdir(self.wiki.db_name, self.wiki.config.temp_dir), real_filename, content, self.wiki.config.fileperms)
def write_notice_file(self): if NoticeFile.NAME in self._enabled: notice_file = self._get_notice_filename() # delnotice. toss any existing file if self.notice is False: if exists(notice_file): os.remove(notice_file) self.notice = "" # addnotice, stuff notice in a file for other jobs etc elif self.notice != "": # notice_dir = self._get_notice_dir() FileUtils.write_file(self.wiki.config.temp_dir, notice_file, self.notice, self.wiki.config.fileperms) # default case. if there is a file get the contents, otherwise # we have empty contents, all good else: if exists(notice_file): self.notice = FileUtils.read_file(notice_file)
def save_feed(self, file_obj): if Feeds.NAME in self._enabled: self.make_dir(self.dump_dir.latest_dir()) filename_and_path = self.dump_dir.web_path(file_obj) web_path = os.path.dirname(filename_and_path) rss_text = self.wiki.config.read_template("feed.xml") % { "chantitle": file_obj.basename, "chanlink": web_path, "chandesc": "Wikimedia dump updates for %s" % self.db_name, "title": web_path, "link": web_path, "description": xml_escape("<a href=\"%s\">%s</a>" % ( filename_and_path, file_obj.filename)), "date": time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) } rss_path = os.path.join(self.dump_dir.latest_dir(), self.db_name + "-latest-" + file_obj.basename + "-rss.xml") self.debugfn("adding rss feed file %s " % rss_path) FileUtils.write_file(self.wiki.config.temp_dir, rss_path, rss_text, self.wiki.config.fileperms)
def save_feed(self, dfname): """ produce an rss feed file for the specified dump output file (dfname) If there is already such a feed, update it only if the date of the dump output file in the feed is not older than the date of dfname, as indicated in the dump dirs/filenames themselves, NOT via stat args: DumpFilename """ if Feeds.NAME in self._enabled: rss_path = os.path.join(self.dump_dir.latest_dir(), self.db_name + "-latest-" + dfname.basename + "-rss.xml") self.make_dir(self.dump_dir.latest_dir()) filename_and_path = self.dump_dir.web_path(dfname) web_path = os.path.dirname(filename_and_path) if self.feed_newer_than_file(rss_path, dfname): return rss_text = self.wiki.config.read_template("feed.xml") % { "chantitle": dfname.basename, "chanlink": web_path, "chandesc": "Wikimedia dump updates for %s" % self.db_name, "title": web_path, "link": web_path, "description": xml_escape("<a href=\"%s\">%s</a>" % ( filename_and_path, dfname.filename)), "date": time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) } self.debugfn("adding rss feed file %s " % rss_path) FileUtils.write_file( FileUtils.wiki_tempdir(self.wiki.db_name, self.wiki.config.temp_dir), rss_path, rss_text, self.wiki.config.fileperms)
def write_notice(self): ''' write notice file if self.notice has contents, or remove if it self.notice is false, or read existing file and stash contents, if self.notice is empty str ''' if Notice.NAME in self._enabled: notice_filepath = self._get_notice_filename() # delnotice. toss any existing file if self.notice is False: if os.path.exists(notice_filepath): os.remove(notice_filepath) self.notice = "" # addnotice, stuff notice in a file for other jobs etc elif self.notice != "": FileUtils.write_file( FileUtils.wiki_tempdir(self.wiki.db_name, self.wiki.config.temp_dir), notice_filepath, self.notice, self.wiki.config.fileperms) # default case. if there is a file get the contents, otherwise # we have empty contents, all good else: if os.path.exists(notice_filepath): self.notice = FileUtils.read_file(notice_filepath)