|
@@ -1,26 +1,31 @@ |
|
|
|
|
|
""" |
|
|
|
|
|
Contains classes and utilities that help publishing a hyde website to |
|
|
|
|
|
distributed version control systems. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
import sys |
|
|
import sys |
|
|
import abc |
|
|
import abc |
|
|
|
|
|
|
|
|
from hyde.loader import load_python_object |
|
|
|
|
|
|
|
|
from hyde.fs import File, Folder |
|
|
|
|
|
from hyde.publisher import Publisher |
|
|
|
|
|
|
|
|
|
|
|
from subprocess import Popen, PIPE |
|
|
|
|
|
|
|
|
class DVCS(object): |
|
|
|
|
|
|
|
|
class DVCS(Publisher): |
|
|
__metaclass__ = abc.ABCMeta |
|
|
__metaclass__ = abc.ABCMeta |
|
|
|
|
|
|
|
|
def __init__(self, path, settings): |
|
|
|
|
|
self.path = path |
|
|
|
|
|
|
|
|
def initialize(self, settings): |
|
|
|
|
|
self.settings = settings |
|
|
|
|
|
self.path = self.site.sitepath.child_folder(settings.path) |
|
|
self.url = settings.url |
|
|
self.url = settings.url |
|
|
self.branch = settings.branch |
|
|
|
|
|
|
|
|
self.branch = getattr(settings, 'branch', 'master') |
|
|
self.switch(self.branch) |
|
|
self.switch(self.branch) |
|
|
self.settings = settings |
|
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod |
|
|
|
|
|
def save_draft(self, message=None): pass |
|
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod |
|
|
@abc.abstractmethod |
|
|
def pull(self): pass |
|
|
def pull(self): pass |
|
|
|
|
|
|
|
|
@abc.abstractmethod |
|
|
@abc.abstractmethod |
|
|
def push(self, branch): pass |
|
|
|
|
|
|
|
|
def push(self): pass |
|
|
|
|
|
|
|
|
@abc.abstractmethod |
|
|
@abc.abstractmethod |
|
|
def commit(self, message): pass |
|
|
def commit(self, message): pass |
|
@@ -29,13 +34,73 @@ class DVCS(object): |
|
|
def switch(self, branch): pass |
|
|
def switch(self, branch): pass |
|
|
|
|
|
|
|
|
@abc.abstractmethod |
|
|
@abc.abstractmethod |
|
|
def add_file(self, path, message=None): pass |
|
|
|
|
|
|
|
|
def add(self, path="."): pass |
|
|
|
|
|
|
|
|
@abc.abstractmethod |
|
|
@abc.abstractmethod |
|
|
def merge(self, branch): pass |
|
|
def merge(self, branch): pass |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def load_dvcs(path, settings): |
|
|
|
|
|
repo_class = load_python_object(settings['type']) |
|
|
|
|
|
return repo_class(path, repo) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def publish(self): |
|
|
|
|
|
super(DVCS, self).publish() |
|
|
|
|
|
if not self.path.exists: |
|
|
|
|
|
raise Exception("The destination repository must exist.") |
|
|
|
|
|
self.site.config.deploy_root_path.copy_contents_to(self.path) |
|
|
|
|
|
self.add() |
|
|
|
|
|
self.commit(self.message) |
|
|
|
|
|
self.push() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Git(DVCS): |
|
|
|
|
|
""" |
|
|
|
|
|
Acts as a publisher to a git repository. Can be used to publish to |
|
|
|
|
|
github pages. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
def add(self, path="."): |
|
|
|
|
|
cmd = Popen('git add "%s"' % path, |
|
|
|
|
|
cwd=str(self.path), stdout=PIPE, shell=True) |
|
|
|
|
|
cmdresult = cmd.communicate()[0] |
|
|
|
|
|
if cmd.returncode: |
|
|
|
|
|
raise Exception(cmdresult) |
|
|
|
|
|
|
|
|
|
|
|
def pull(self): |
|
|
|
|
|
self.switch(self.branch) |
|
|
|
|
|
cmd = Popen("git pull origin %s" % self.branch, |
|
|
|
|
|
cwd=str(self.path), |
|
|
|
|
|
stdout=PIPE, |
|
|
|
|
|
shell=True) |
|
|
|
|
|
cmdresult = cmd.communicate()[0] |
|
|
|
|
|
if cmd.returncode: |
|
|
|
|
|
raise Exception(cmdresult) |
|
|
|
|
|
|
|
|
|
|
|
def push(self): |
|
|
|
|
|
cmd = Popen("git push origin %s" % self.branch, |
|
|
|
|
|
cwd=str(self.path), stdout=PIPE, |
|
|
|
|
|
shell=True) |
|
|
|
|
|
cmdresult = cmd.communicate()[0] |
|
|
|
|
|
if cmd.returncode: |
|
|
|
|
|
raise Exception(cmdresult) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def commit(self, message): |
|
|
|
|
|
cmd = Popen('git commit -a -m"%s"' % message, |
|
|
|
|
|
cwd=str(self.path), stdout=PIPE, shell=True) |
|
|
|
|
|
cmdresult = cmd.communicate()[0] |
|
|
|
|
|
if cmd.returncode: |
|
|
|
|
|
raise Exception(cmdresult) |
|
|
|
|
|
|
|
|
|
|
|
def switch(self, branch): |
|
|
|
|
|
self.branch = branch |
|
|
|
|
|
cmd = Popen('git checkout %s' % branch, |
|
|
|
|
|
cwd=str(self.path), stdout=PIPE, shell=True) |
|
|
|
|
|
cmdresult = cmd.communicate()[0] |
|
|
|
|
|
if cmd.returncode: |
|
|
|
|
|
raise Exception(cmdresult) |
|
|
|
|
|
|
|
|
|
|
|
def merge(self, branch): |
|
|
|
|
|
cmd = Popen('git merge %s' % branch, |
|
|
|
|
|
cwd=str(self.path), stdout=PIPE, shell=True) |
|
|
|
|
|
cmdresult = cmd.communicate()[0] |
|
|
|
|
|
if cmd.returncode: |
|
|
|
|
|
raise Exception(cmdresult) |