Beispiel #1
0
    def change(self, **kwargs):
        added = kwargs.get('added', {})
        modified = kwargs.get('modified', {})
        deleted = kwargs.get('deleted', [])
        renamed = kwargs.get('renamed', {})
        plugins = kwargs.get('call_plugins', True)

        for repofile in added:
            self.save_file(repofile, added[repofile])
        for repofile in modified:
            self.save_file(repofile, modified[repofile])
        for repofile in deleted:
            self.delete_file(repofile)

        if plugins:
            # verify that renamed is correct
            assert len(set(renamed.values())) == len(renamed)

            for oldfile in renamed:
                assert oldfile in deleted
                deleted.remove(oldfile)

            for newfile in renamed.values():
                assert newfile in added
                added.remove(newfile)

            changed = ChangedFiles(added=list(added.keys()),
                                   modified=list(modified.keys()),
                                   deleted=deleted,
                                   renamed=renamed)
            call_plugins('on_files_changed', changed)
Beispiel #2
0
    def test_autodates_adjusts_dates(self):
        self.site.save_file("content/cooking/italian/spaghetti.txt", SPAGHETTI)
        changed = ChangedFiles(added=["content/cooking/italian/spaghetti.txt"], modified=["content/reading/hamlet.txt"])
        call_plugins("on_pre_sync", changed)

        self.assertIn("create_time: 2015-09-13", self.site.load_file("content/cooking/italian/spaghetti.txt"))
        self.assertIn("modified_time: 2015-09-13", self.site.load_file("content/cooking/italian/spaghetti.txt"))

        self.assertIn("create_time: 2015-09-13", self.site.load_file("content/reading/hamlet.txt"))
        self.assertIn("modified_time: 2015-09-13", self.site.load_file("content/reading/hamlet.txt"))
Beispiel #3
0
    def test_autotags_honours_tag_override(self):
        self.site.save_file('content/cooking/italian/spaghetti.txt', SPAGHETTI)
        changed = utils.ChangedFiles(added=['content/cooking/italian/spaghetti.txt'])

        mock = Mock(return_value='orange,apple')
        with patch('builtins.input', mock):
            call_plugins('on_pre_sync', changed)

        self.assertIn('tags: orange,apple',
                       self.site.load_file('content/cooking/italian/spaghetti.txt'))
Beispiel #4
0
    def test_autotags_leaves_existing_tags_alone(self):
        self.site.save_file('content/cooking/italian/linguine.txt', LINGUINE)
        changed = utils.ChangedFiles(added=['content/cooking/italian/linguine.txt'])

        mock = Mock(return_value='')
        with patch('builtins.input', mock):
            call_plugins('on_pre_sync', changed)

        self.assertIn('tags: italian,pasta',
                       self.site.load_file('content/cooking/italian/linguine.txt'))
Beispiel #5
0
def _sync(strict, addnew, push, message):
    if not strict:
        # if addnew is True, this means we need to add all untracked files
        # to the index.  The -A will do that.  Otheriwse we just do a -u,
        # which will only update the tracked files.
        if addnew:
            vc_add_tracked_and_new()
        else:
            vc_add_tracked()

        # at this point we should have an almost snapshot of what we want
        # to commit in the index.  It's "almost" because we now may want
        # to fix up or add the timestamps.
        call_plugins('on_pre_sync', vc_status())

        # readjust the index with whatever changes were made by
        # the pre_sync plugins
        vc_add_tracked()
    vc_commit(message)
    if push:
        vc_push()
Beispiel #6
0
 def walk(self):
     """Perform a walk (i.e. visit each article in the store) and run the
     plugins to process the articles.
     """
     call_plugins('on_pre_walk')
     for fullname in self._walk():
         article = self.fetch_article(fullname)
         call_plugins('on_visit_article', article)
     call_plugins('on_post_walk')
Beispiel #7
0
def _handle_cli_init(manager):
    current_app.preprocess_request()
    call_plugins('on_cli_init', manager)
Beispiel #8
0
    def test_autodates_uses_existing_create_time(self):
        changed = ChangedFiles(modified=["content/cooking/indian/madras.txt"])
        call_plugins("on_pre_sync", changed)

        self.assertIn("create_time: 2007-06-01", self.site.load_file("content/cooking/indian/madras.txt"))
        self.assertIn("modified_time: 2015-09-13", self.site.load_file("content/cooking/indian/madras.txt"))
Beispiel #9
0
def _git_files_changed(tree1, tree2):
    changed = _extract_diff_tree_files(tree1, tree2)
    call_plugins('on_files_changed', changed)