Ejemplo n.º 1
0
    def new (self):
        
        """
        Called when user wants to create a new post 
        """

        bologna = Bologna(os.getcwd())

        # Use the environment editor, if not fouind, use our config
        editor = bologna.config['general']['editor']
        if 'EDITOR' in os.environ:
            editor = os.environ['EDITOR']
        
        if len(self.args) == 0:
            posts = bologna.posts
            path = 'bologna/posts/%s.post' % len(posts) + 1
        else:
            path = self.args[0]
        
        if os.path.exists(path):
            logging.error('Path %s already exists' % path)
            return

        # Now create a new post
        p = Post(
            path=os.path.join(bologna.path, path),
            title = 'Your New Post',
            contents = 'Enter your post body using markdown here'
        )
        p.write()
        subprocess.call('%s %s' % (editor, p.path), shell=True)
Ejemplo n.º 2
0
    def posts(self):

        """
        Returns a list of posts 
        """

        if self._posts != None:
            return self._posts

        postdir = os.path.join(self.path, "bologna/posts")
        posts = []

        for f in os.listdir(postdir):

            if f.endswith(".post"):
                p = Post(path=os.path.join(postdir, f))
                p.read()
                posts.append(p)

        self._posts = posts
        return posts
Ejemplo n.º 3
0
    def create(cls, path):

        """
        Creates a Bologna repository at the given path. 
        
        Throws an exception if it encounters an error while
        creating the repository. All Bologna related exceptions will be of
        type BolognaException. Does not catch OSErrors, or other exceptions
        that may occur.
        """

        # Perform our basic checks
        if cls.exists(path):
            raise BolognaException, "Repository exists at given path %s" % path

        # Copy our base data and make the folders we require, could throw
        # an error, if it does, the user of the library must catch it.
        bologna_install_path = os.path.join(os.path.abspath(os.path.split(__file__)[0]), "..")
        shutil.copytree(os.path.join(bologna_install_path, "base_data"), os.path.join(path, "bologna"))
        os.makedirs(os.path.join(path, "html"))
        f = open(os.path.join(path, ".bologna"), "w")
        f.write("bologna repo")
        f.close()

        # Create our post with its tags
        test_post = Post(
            title="Welcome to your blog!",
            contents="123 Here we go :D",
            path=os.path.join(path, "bologna/posts/welcome.post"),
            published=True,
        )

        # Attempt to write the post to file system
        try:
            test_post.write()
        except ValidationException, e:
            raise BolognaException, e