示例#1
0
    def _prepare(cls, create, **kwargs):

        light = kwargs.pop('light', False)
        tuto = super(BigTutorialFactory, cls)._prepare(create, **kwargs)
        path = tuto.get_path()
        real_content = content
        if light:
            real_content = content_light
        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        man = export_tutorial(tuto)
        repo = Repo.init(path, bare=False)
        repo = Repo(path)

        f = open(os.path.join(path, 'manifest.json'), "w")
        f.write(json_writer.dumps(man, indent=4, ensure_ascii=False).encode('utf-8'))
        f.close()
        f = open(os.path.join(path, tuto.introduction), "w")
        f.write(real_content.encode('utf-8'))
        f.close()
        f = open(os.path.join(path, tuto.conclusion), "w")
        f.write(real_content.encode('utf-8'))
        f.close()
        repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion])
        cm = repo.index.commit("Init Tuto")

        tuto.sha_draft = cm.hexsha
        tuto.sha_beta = None
        tuto.gallery = GalleryFactory()
        for author in tuto.authors.all():
            UserGalleryFactory(user=author, gallery=tuto.gallery)
        return tuto
示例#2
0
    def _prepare(cls, create, **kwargs):
        tuto = super(MiniTutorialFactory, cls)._prepare(create, **kwargs)
        path = tuto.get_path()
        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        man = export_tutorial(tuto)
        repo = Repo.init(path, bare=False)
        repo = Repo(path)

        file = open(os.path.join(path, 'manifest.json'), "w")
        file.write(
            json_writer.dumps(
                man,
                indent=4,
                ensure_ascii=False).encode('utf-8'))
        file.close()
        file = open(os.path.join(path, tuto.introduction), "w")
        file.write(contenu.encode('utf-8'))
        file.close()
        file = open(os.path.join(path, tuto.conclusion), "w")
        file.write(contenu.encode('utf-8'))
        file.close()

        repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion])
        cm = repo.index.commit("Init Tuto")

        tuto.sha_draft = cm.hexsha
        return tuto
示例#3
0
    def _prepare(cls, create, **kwargs):
        tuto = super(MiniTutorialFactory, cls)._prepare(create, **kwargs)
        path = tuto.get_path()
        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        man = export_tutorial(tuto)
        repo = Repo.init(path, bare=False)
        repo = Repo(path)

        file = open(os.path.join(path, 'manifest.json'), "w")
        file.write(
            json_writer.dumps(
                man,
                indent=4,
                ensure_ascii=False).encode('utf-8'))
        file.close()
        file = open(os.path.join(path, tuto.introduction), "w")
        file.write(u'Test')
        file.close()
        file = open(os.path.join(path, tuto.conclusion), "w")
        file.write(u'Test')
        file.close()

        repo.index.add(['manifest.json', tuto.introduction, tuto.conclusion])
        cm = repo.index.commit("Init Tuto")

        tuto.sha_draft = cm.hexsha
        return tuto
示例#4
0
文件: models.py 项目: Ge0/zds-site
    def dump_json(self, path=None):
        if path is None:
            man_path = os.path.join(self.get_path(), 'manifest.json')
        else:
            man_path = path

        dct = export_tutorial(self)
        data = json_writer.dumps(dct, indent=4, ensure_ascii=False)
        json_data = open(man_path, "w")
        json_data.write(data.encode('utf-8'))
        json_data.close()
示例#5
0
    def dump_json(self, path=None):
        if path is None:
            man_path = os.path.join(self.get_path(), 'manifest.json')
        else:
            man_path = path

        dct = export_tutorial(self)
        data = json_writer.dumps(dct, indent=4, ensure_ascii=False)
        json_data = open(man_path, "w")
        json_data.write(data.encode('utf-8'))
        json_data.close()
示例#6
0
    def _prepare(cls, create, **kwargs):
        light = kwargs.pop('light', False)
        part = super(PartFactory, cls)._prepare(create, **kwargs)
        tutorial = kwargs.pop('tutorial', None)

        real_content = content
        if light:
            real_content = content_light

        path = part.get_path()
        repo = Repo(part.tutorial.get_path())

        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        part.introduction = os.path.join(part.get_phy_slug(), 'introduction.md')
        part.conclusion = os.path.join(part.get_phy_slug(), 'conclusion.md')
        part.save()

        f = open(os.path.join(tutorial.get_path(), part.introduction), "w")
        f.write(real_content.encode('utf-8'))
        f.close()
        repo.index.add([part.introduction])
        f = open(os.path.join(tutorial.get_path(), part.conclusion), "w")
        f.write(real_content.encode('utf-8'))
        f.close()
        repo.index.add([part.conclusion])

        if tutorial:
            tutorial.save()

            man = export_tutorial(tutorial)
            f = open(os.path.join(tutorial.get_path(), 'manifest.json'), "w")
            f.write(
                json_writer.dumps(
                    man,
                    indent=4,
                    ensure_ascii=False).encode('utf-8'))
            f.close()

            repo.index.add(['manifest.json'])

        cm = repo.index.commit("Init Part")

        if tutorial:
            tutorial.sha_draft = cm.hexsha
            tutorial.save()

        return part
示例#7
0
    def _prepare(cls, create, **kwargs):
        part = super(PartFactory, cls)._prepare(create, **kwargs)
        tutorial = kwargs.pop('tutorial', None)

        path = part.get_path()
        repo = Repo(part.tutorial.get_path())

        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        part.introduction = os.path.join(part.get_phy_slug(), 'introduction.md')
        part.conclusion = os.path.join(part.get_phy_slug(), 'conclusion.md')
        part.save()

        f = open(os.path.join(tutorial.get_path(), part.introduction), "w")
        f.write(contenu.encode('utf-8'))
        f.close()
        repo.index.add([part.introduction])
        f = open(os.path.join(tutorial.get_path(), part.conclusion), "w")
        f.write(contenu.encode('utf-8'))
        f.close()
        repo.index.add([part.conclusion])

        if tutorial:
            tutorial.save()

            man = export_tutorial(tutorial)
            f = open(os.path.join(tutorial.get_path(), 'manifest.json'), "w")
            f.write(
                json_writer.dumps(
                    man,
                    indent=4,
                    ensure_ascii=False).encode('utf-8'))
            f.close()

            repo.index.add(['manifest.json'])

        cm = repo.index.commit("Init Part")

        if tutorial:
            tutorial.sha_draft = cm.hexsha
            tutorial.save()

        return part
示例#8
0
    def _prepare(cls, create, **kwargs):
        chapter = super(ChapterFactory, cls)._prepare(create, **kwargs)
        tutorial = kwargs.pop('tutorial', None)
        part = kwargs.pop('part', None)

        path = chapter.get_path()

        if not os.path.isdir(path):
            os.makedirs(path, mode=0o777)

        if tutorial:
            chapter.introduction = ''
            chapter.conclusion = ''
            tutorial.save()
            repo = Repo(tutorial.get_path())

            man = export_tutorial(tutorial)
            f = open(os.path.join(tutorial.get_path(), 'manifest.json'), "w")
            f.write(
                json_writer.dumps(
                    man,
                    indent=4,
                    ensure_ascii=False).encode('utf-8'))
            f.close()
            repo.index.add(['manifest.json'])

        elif part:
            chapter.introduction = os.path.join(
                part.get_phy_slug(),
                chapter.get_phy_slug(),
                'introduction.md')
            chapter.conclusion = os.path.join(
                part.get_phy_slug(),
                chapter.get_phy_slug(),
                'conclusion.md')
            chapter.save()
            f = open(
                os.path.join(
                    part.tutorial.get_path(),
                    chapter.introduction),
                "w")
            f.write(u'Test')
            f.close()
            f = open(
                os.path.join(
                    part.tutorial.get_path(),
                    chapter.conclusion),
                "w")
            f.write(u'Test')
            f.close()
            part.tutorial.save()
            repo = Repo(part.tutorial.get_path())

            man = export_tutorial(part.tutorial)
            f = open(
                os.path.join(
                    part.tutorial.get_path(),
                    'manifest.json'),
                "w")
            f.write(
                json_writer.dumps(
                    man,
                    indent=4,
                    ensure_ascii=False).encode('utf-8'))
            f.close()

            repo.index.add([chapter.introduction, chapter.conclusion])
            repo.index.add(['manifest.json'])

        cm = repo.index.commit("Init Chapter")

        if tutorial:
            tutorial.sha_draft = cm.hexsha
            tutorial.save()
            chapter.tutorial = tutorial
        elif part:
            part.tutorial.sha_draft = cm.hexsha
            part.tutorial.save()
            part.save()
            chapter.part = part

        return chapter