예제 #1
0
파일: autodates.py 프로젝트: drivet/yawt
def _fix_dates_for_article(repofile):
    abs_article_file = os.path.join(current_app.yawt_root_dir, repofile)
    post = frontmatter.load(abs_article_file)
    now = _now()
    if 'create_time' not in post.metadata:
        post['create_time'] = now
    post['modified_time'] = now
    save_file(abs_article_file, frontmatter.dumps(post, Dumper=ExplicitDumper))
예제 #2
0
파일: test_article.py 프로젝트: drivet/yawt
 def test_make_article_fills_basic_info(self):
     save_file('/tmp/stuff/article_file.txt', 'blah')
     article = make_article('stuff/article_file',
                            '/tmp/stuff/article_file.txt')
     self.assertEquals('stuff/article_file', article.info.fullname)
     self.assertEquals('stuff', article.info.category)
     self.assertEquals('article_file', article.info.slug)
     self.assertEquals('txt', article.info.extension)
     self.assertEquals('blah', article.content)
예제 #3
0
파일: test_article.py 프로젝트: drivet/yawt
 def test_make_article_has_no_content_when_file_is_empty(self):
     save_file('/tmp/stuff/article_file.txt', '')
     article = make_article('stuff/article_file',
                            '/tmp/stuff/article_file.txt')
     self.assertEquals('stuff/article_file', article.info.fullname)
     self.assertEquals('stuff', article.info.category)
     self.assertEquals('article_file', article.info.slug)
     self.assertEquals('txt', article.info.extension)
     self.assertEquals('', article.content)
예제 #4
0
파일: autotags.py 프로젝트: drivet/yawt
def _add_tags_for_article(repofile, searcher):
    abs_article_file = os.path.join(current_app.yawt_root_dir, repofile)
    post = frontmatter.load(abs_article_file)
    if 'tags' not in post.metadata:
        keywords = [keyword for keyword, _
                    in searcher.key_terms_from_text("content", post.content,
                                                    numterms=3)]
        keyword_str = ",".join(keywords)
        usertags = input('Enter tags (default '+keyword_str+'): ')
        tags = usertags or keyword_str
        post['tags'] = tags
        save_file(abs_article_file, frontmatter.dumps(post))
예제 #5
0
파일: test_article.py 프로젝트: drivet/yawt
    def test_make_article_loads_date_types_as_int(self):
        article_text = """---
date: 2015-05-16 01:52:57.906737
---

blah
"""
        save_file('/tmp/stuff/article_file.txt', article_text)
        article = make_article('stuff/article_file',
                               '/tmp/stuff/article_file.txt',
                               meta_types={'date': 'iso8601'})
        self.assertTrue(isinstance(article.info.date, int))
예제 #6
0
파일: test_article.py 프로젝트: drivet/yawt
    def test_make_article_loads_list_typed_metadata(self):
        article_text = """---
tags: tag1,tag2,tag3
---

blah
"""
        save_file('/tmp/stuff/article_file.txt', article_text)
        article = make_article('stuff/article_file',
                               '/tmp/stuff/article_file.txt',
                               meta_types={'tags': 'list'})
        self.assertTrue(article.info.tags, ['tag1', 'tag2', 'tag3'])
예제 #7
0
파일: __init__.py 프로젝트: drivet/yawt
    def initialize(self):
        self.site_root = tempfile.mkdtemp()

        for folder in self.folders:
            os.makedirs(os.path.join(self.site_root, folder))

        for the_file in self.files.keys():
            abs_filename = os.path.join(self.site_root, the_file)
            content = self.files[the_file]
            if isinstance(content, tuple):
                save_file(abs_filename, dump_post(content[0], content[1]))
            else:
                save_file(abs_filename, content)
예제 #8
0
파일: test_article.py 프로젝트: drivet/yawt
    def test_make_article_loads_simple_metadata(self):
        article_text = """---
title: this is a title
count: 76
foo: [5, 'dd']
---

blah
"""
        save_file('/tmp/stuff/article_file.txt', article_text)
        article = make_article('stuff/article_file',
                               '/tmp/stuff/article_file.txt')
        self.assertTrue(article.info.title, 'this is a title')
        self.assertTrue(article.info.count, 76)
        self.assertTrue(article.info.foo, [5, 'dd'])
예제 #9
0
파일: site_manager.py 프로젝트: drivet/yawt
    def initialize(self):
        """Set up an empty blog folder"""
        if os.path.exists(self.root_dir):
            raise SiteExistsError(self.root_dir)

        ensure_path(self._content_root())
        ensure_path(self._draft_root())
        ensure_path(self._template_root())
        config_content = '# put configuration here'
        save_file(os.path.join(self.root_dir, 'config.py'), config_content)
        template_contents = yawt.default_templates.default_article_template
        self._save_template('article', 'html', template_contents)
        template_404_contents = yawt.default_templates.default_404_template
        self._save_template('404', 'html', template_404_contents)
        files = ['config.py', 'article.html', '404.html']
        return call_plugins_arg('on_new_site', files)
예제 #10
0
파일: autotags.py 프로젝트: drivet/yawt
def _add_tags_for_indexed_article(indexed_file, edit):
    root_dir = current_app.yawt_root_dir
    if not indexed_file.startswith(content_folder()):
        print("file must be in content folder")
        return

    searcher = _whoosh().searcher
    docnums = searcher.document_numbers(fullname=fullname(indexed_file))
    keywords = [keyword for keyword, _
                in searcher.key_terms(docnums, "content", numterms=3)]
    keyword_str = ",".join(keywords)
    print("Tags: "+keyword_str)
    if edit:
        abs_article_file = os.path.join(root_dir, indexed_file)
        post = frontmatter.load(abs_article_file)
        post['tags'] = keyword_str
        save_file(abs_article_file, frontmatter.dumps(post))
예제 #11
0
 def setUp(self):
     self.old_facebook = yawtext.facebook.facepy
     yawtext.facebook.facepy = fake_facebook
     fake_facebook.clear()
     save_file('/tmp/fbtoken', access_token)
예제 #12
0
파일: test_twitter.py 프로젝트: drivet/yawt
 def setUp(self):
     self.old_tweepy = yawtext.twitter.tweepy
     yawtext.twitter.tweepy = fake_tweepy
     fake_tweepy.clear()
     save_file('/tmp/twittercred.yml', twittercred)
예제 #13
0
파일: siteutils.py 프로젝트: drivet/yawt
 def save_state_file(self, rel_filename, content=''):
     abs_state_file = os.path.join(self.state_root, rel_filename)
     save_file(abs_state_file, content)
예제 #14
0
파일: siteutils.py 프로젝트: drivet/yawt
 def save_template(self, rel_filename, template=''):
     abs_template_file = os.path.join(self.abs_template_root(), rel_filename)
     save_file(abs_template_file, template)
예제 #15
0
파일: siteutils.py 프로젝트: drivet/yawt
 def save_content(self, rel_filename, content=''):
     abs_content_file = os.path.join(self.abs_content_root(), rel_filename)
     save_file(abs_content_file, content)
예제 #16
0
파일: __init__.py 프로젝트: drivet/yawt
 def _save_summary(self):
     save_file(self._abs_summary_file(), jsonpickle.encode(self.summary))
예제 #17
0
파일: vc.py 프로젝트: drivet/yawt
 def on_new_site(self, files):
     """When a new site is created, we'll save a gitignore file so we can
     ignore the _state directory
     """
     filename = os.path.join(current_app.yawt_root_dir, vc_ignore_file())
     save_file(filename, '_state')
예제 #18
0
파일: test_article.py 프로젝트: drivet/yawt
 def test_make_article_loads_file_metadata(self):
     save_file('/tmp/stuff/article_file.txt', 'blah')
     article = make_article('stuff/article_file',
                            '/tmp/stuff/article_file.txt')
     self.assertTrue(isinstance(article.info.create_time, float))
     self.assertTrue(isinstance(article.info.modified_time, float))
예제 #19
0
파일: __init__.py 프로젝트: drivet/yawt
 def save_file(self, repofile, contents):
     save_file(os.path.join(self.site_root, repofile), contents)
예제 #20
0
파일: site_manager.py 프로젝트: drivet/yawt
 def _save_template(self, name, flavour, contents):
     save_file(self._template_ext2file(name, flavour), contents)