Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
This **EXPERIMENTAL** plugin tries to make it easy to keep your site in a version control system. | ||
|
||
**REMEMBER**, this is a first iteration, it's probably buggy, so be careful, and only use it | ||
if you are experienced with your VCS, ok? | ||
|
||
How to use it: | ||
|
||
1. Choose your favourite VCS between git, bzr, subversion, mercurial. | ||
2. Initialize the repo in your site (for example: ``git init .``) | ||
3. Install this plugin: ``nikola plugin -i vcs`` | ||
4. Run ``nikola vcs`` | ||
5. Check what happened (for example: ``git status`` and ``git log``) | ||
6. Use your site as usual, creating posts, adding stuff or removing it | ||
7. GOTO 4. | ||
|
||
What it should do: | ||
|
||
1. Add a lot of stuff to the repo: | ||
|
||
* All your posts | ||
* All your pages | ||
* All your galleries' images | ||
* All your listings | ||
* All your static files | ||
* Your themes | ||
* Your plugins | ||
* Your conf.py | ||
|
||
2. Remove stuff if you removed it | ||
3. Commit stuff if you changed it | ||
|
||
What it should **NOT** do: | ||
|
||
1. Lose your data | ||
2. Push it anywhere (yet) | ||
3. Manage your output (consider ``github_deploy`` would not like it!) | ||
|
||
Please report anything missing, or any ideas on how to improve this, where you want this to go | ||
by [filing issues](https://github.com/getnikola/plugins/issues). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
anyvc | ||
py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Core] | ||
Name = vcs | ||
Module = vcs | ||
|
||
[Documentation] | ||
Author = Roberto Alsina | ||
Version = 1.0 | ||
Website = https://getnikola.com | ||
Description = Site vcs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright © 2012-2015 Roberto Alsina and others. | ||
|
||
# Permission is hereby granted, free of charge, to any | ||
# person obtaining a copy of this software and associated | ||
# documentation files (the "Software"), to deal in the | ||
# Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the | ||
# Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice | ||
# shall be included in all copies or substantial portions of | ||
# the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
from __future__ import print_function | ||
import os | ||
|
||
from py.path import local | ||
from anyvc import workdir | ||
|
||
from nikola.plugin_categories import Command | ||
from nikola.utils import get_logger | ||
|
||
|
||
def get_path_list(path): | ||
'''Walk path and return a list of everythin in it.''' | ||
paths = [] | ||
for root, dirs, files in os.walk(path, followlinks=True): | ||
for fname in files: | ||
fpath = os.path.join(root, fname) | ||
paths.append(fpath) | ||
return list(set(paths)) | ||
|
||
|
||
class CommandVCS(Command): | ||
""" Site status. """ | ||
name = "vcs" | ||
|
||
doc_purpose = "display site status" | ||
doc_description = "Show information about the posts and site deployment." | ||
logger = None | ||
cmd_options = [] | ||
|
||
def _execute(self, options, args): | ||
logger = get_logger('vcs', self.site.loghandlers) | ||
self.site.scan_posts() | ||
|
||
repo_path = local('.') | ||
wd = workdir.open(repo_path) | ||
|
||
# See if anything got deleted | ||
del_paths = [] | ||
flag = False | ||
for s in wd.status(): | ||
if s.state == 'removed': | ||
if not flag: | ||
logger.info('Found deleted files') | ||
flag = True | ||
logger.info('DEL => {}', s.relpath) | ||
del_paths.append(s.relpath) | ||
|
||
if flag: | ||
logger.info('Marking as deleted') | ||
wd.remove(paths=del_paths) | ||
wd.commit(message='Deleted Files', paths=del_paths) | ||
|
||
# Collect all paths that should be kept under control | ||
# Post and page sources | ||
paths = [] | ||
for lang in self.site.config['TRANSLATIONS']: | ||
for p in self.site.timeline: | ||
paths.extend(p.fragment_deps(lang)) | ||
|
||
# Files in general | ||
for k, v in self.site.config['FILES_FOLDERS'].items(): | ||
paths.extend(get_path_list(k)) | ||
for k, v in self.site.config['LISTINGS_FOLDERS'].items(): | ||
paths.extend(get_path_list(k)) | ||
for k, v in self.site.config['GALLERY_FOLDERS'].items(): | ||
paths.extend(get_path_list(k)) | ||
|
||
# Themes and plugins | ||
for p in ['plugins', 'themes']: | ||
paths.extend(get_path_list(p)) | ||
|
||
# Add them to the VCS | ||
paths = list(set(paths)) | ||
wd.add(paths=paths) | ||
|
||
flag = False | ||
for s in wd.status(): | ||
if s.state == 'added': | ||
if not flag: | ||
logger.info('Found new files') | ||
flag = True | ||
logger.info('NEW => {}', s.relpath) | ||
|
||
logger.info('Committing changes') | ||
wd.commit(message='Updated files') |