コード例 #1
0
    def generate_visible(self):
        visible_pages = [p.page for p in self.pages_set.filter(visible=True)]
        abs_path = "%s/%s" % (self.get_root_path(), self.slug)

        # txt
        all_txt = fs.open("%s-visible.txt" % abs_path, "w")
        pages = {}
        for f in fss.listdir(self.get_root_path())[1]:  # [0]: dirs, [1]: files
            if f[-4:] == ".txt" and f != "%s.txt" % self.slug:
                m = RE_PAGE.match(f)
                if m:
                    k = int(m.group(1))
                    if k in visible_pages:
                        pages[k] = f
        for k in pages:
            f = pages[k]
            tmp_txt = "%s/%s" % (self.get_root_path(), f)
            fss.write_file(tmp_txt, all_txt)
        fss.close_file(all_txt)

        # pdf
        pages_str = " ".join(map(str, visible_pages))
        command = "pdftk {}.pdf cat {} output {}-visible.pdf".format(abs_path, pages_str, abs_path)
        Popen(command, shell=True, stdout=PIPE).stdout.read()

        abs_url = "%s/%s" % (self.get_root_url(), self.slug)
        return ("%s-visible.txt" % abs_url, "%s-visible.pdf" % abs_url)
コード例 #2
0
 def regenerate_ts(self, ts="", files=[]):
     # reconcatenate all text files in a specific ts
     all_txt = "%s/%s--%s.txt" % (self.get_root_path(), self.slug, ts)
     for f in files:
         tmp_txt = "%s/%s" % (self.get_root_path(), f)
         fss.write_file(tmp_txt, all_txt)
     fss.close_file(all_txt)
コード例 #3
0
 def regenerate(self):
     # reconcatenate all text files
     all_txt = "%s/%s.txt" % (self.get_root_path(), self.slug)
     pages = {}
     for f in fss.listdir(self.get_root_path())[1]:  # [0]: dirs, [1]: files
         if f[-4:] == ".txt" and f != "%s.txt" % self.slug:
             m = RE_PAGE.match(f)
             if m:
                 k = int(m.group(1))
                 pages[k] = f
     for k in pages:
         f = pages[k]
         tmp_txt = "%s/%s" % (self.get_root_path(), f)
         fss.write_file(tmp_txt, all_txt)
     fss.close_file(all_txt)
コード例 #4
0
    def generate(self):
        # concatenate all text files
        ts = datetime.now()
        all_txt = "%s/%s.txt" % (self.get_root_path(), self.slug)
        self.page_count = 0
        self.pages_set.all().delete()
        pages = {}
        for f in fss.listdir(self.get_root_path())[1]:  # [0]: dirs, [1]: files
            if f[-4:] == ".txt" and f != "%s.txt" % self.slug:
                m = RE_PAGE.match(f)
                if m:
                    k = int(m.group(1))
                    pages[k] = f
        mod_pags_orig = {}
        mod_pags_curr = {}
        for k in pages:
            f = pages[k]
            self.page_count += 1
            tmp_txt = "%s/%s" % (self.get_root_path(), f)
            fss.write_file(tmp_txt, all_txt)
            page = Page(document=self, page=RE_PAGE.match(f).group(1), modified=ts)
            page.save()

            filepath_orig = "%s/%s_%s-%s.txt" % (self.document.get_root_path(), self.document.slug, k, zeros)
            fss.copy_file(tmp_txt, filepath_orig)

            text_url = self.document.text_page_url
            mod_pags_orig[self.page_count] = text_url.replace("%(page)s", "{}-{}".format(self.page_count, zeros))
            mod_pags_curr[self.page_count] = text_url.replace("%(page)s", "{}".format(self.page_count))
        Edition.objects.create(
            document=self.document,
            author=self.document.document.owner,
            comment="Original version",
            modified_pages=mod_pags_orig,
            date_string=zeros,
        )
        Edition.objects.create(
            document=self.document,
            author=self.document.document.owner,
            comment="Current version",
            modified_pages=mod_pags_curr,
            date_string=nines,
        )
        fss.close_file(all_txt)