Merge branch 'master' into markdown-it
This commit is contained in:
commit
1261d7c2e9
|
@ -28,7 +28,6 @@ ENV GEVENT_RESOLVER=ares
|
||||||
ENV REALMS_ENV=docker
|
ENV REALMS_ENV=docker
|
||||||
ENV REALMS_WIKI_PATH=/home/wiki/data/repo
|
ENV REALMS_WIKI_PATH=/home/wiki/data/repo
|
||||||
ENV REALMS_DB_URI='sqlite:////home/wiki/data/wiki.db'
|
ENV REALMS_DB_URI='sqlite:////home/wiki/data/wiki.db'
|
||||||
ENV REALMS_SQLALCHEMY_DATABASE_URI=${REALMS_DB_URI}
|
|
||||||
|
|
||||||
RUN mkdir /home/wiki/data && touch /home/wiki/data/.a
|
RUN mkdir /home/wiki/data && touch /home/wiki/data/.a
|
||||||
VOLUME /home/wiki/data
|
VOLUME /home/wiki/data
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Config(object):
|
||||||
BASE_URL = 'http://localhost'
|
BASE_URL = 'http://localhost'
|
||||||
SITE_TITLE = "Realms"
|
SITE_TITLE = "Realms"
|
||||||
|
|
||||||
# https://pythonhosted.org/Flask-SQLAlchemy/config.html#connection-uri-format
|
# http://flask-sqlalchemy.pocoo.org/config/#connection-uri-format
|
||||||
DB_URI = 'sqlite:////tmp/wiki.db'
|
DB_URI = 'sqlite:////tmp/wiki.db'
|
||||||
# DB_URI = 'mysql://scott:tiger@localhost/mydatabase'
|
# DB_URI = 'mysql://scott:tiger@localhost/mydatabase'
|
||||||
# DB_URI = 'postgresql://scott:tiger@localhost/mydatabase'
|
# DB_URI = 'postgresql://scott:tiger@localhost/mydatabase'
|
||||||
|
|
|
@ -40,7 +40,7 @@ providers = {
|
||||||
'field_map': {
|
'field_map': {
|
||||||
'id': 'id',
|
'id': 'id',
|
||||||
'username': 'login',
|
'username': 'login',
|
||||||
'email': 'email'
|
'email': lambda(data): data.get('email') or data['login'] + '@users.noreply.github.com'
|
||||||
},
|
},
|
||||||
'token_name': 'access_token'
|
'token_name': 'access_token'
|
||||||
},
|
},
|
||||||
|
@ -118,6 +118,8 @@ class User(BaseUser):
|
||||||
def get_value(d, key):
|
def get_value(d, key):
|
||||||
if isinstance(key, basestring):
|
if isinstance(key, basestring):
|
||||||
return d.get(key)
|
return d.get(key)
|
||||||
|
elif callable(key):
|
||||||
|
return key(d)
|
||||||
# key should be list here
|
# key should be list here
|
||||||
val = d.get(key.pop(0))
|
val = d.get(key.pop(0))
|
||||||
if len(key) == 0:
|
if len(key) == 0:
|
||||||
|
|
|
@ -2,11 +2,9 @@ import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
import ghdiff
|
import ghdiff
|
||||||
import gittle.utils
|
|
||||||
import yaml
|
import yaml
|
||||||
from gittle import Gittle
|
|
||||||
from dulwich.object_store import tree_lookup_path
|
from dulwich.object_store import tree_lookup_path
|
||||||
from dulwich.repo import NotGitRepository
|
from dulwich.repo import Repo, NotGitRepository
|
||||||
from realms.lib.util import cname_to_filename, filename_to_cname
|
from realms.lib.util import cname_to_filename, filename_to_cname
|
||||||
from realms import cache
|
from realms import cache
|
||||||
from realms.lib.hook import HookMixin
|
from realms.lib.hook import HookMixin
|
||||||
|
@ -23,17 +21,13 @@ class Wiki(HookMixin):
|
||||||
default_committer_name = 'Anon'
|
default_committer_name = 'Anon'
|
||||||
default_committer_email = 'anon@anon.anon'
|
default_committer_email = 'anon@anon.anon'
|
||||||
index_page = 'home'
|
index_page = 'home'
|
||||||
gittle = None
|
|
||||||
repo = None
|
repo = None
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
try:
|
try:
|
||||||
self.gittle = Gittle(path)
|
self.repo = Repo(path)
|
||||||
except NotGitRepository:
|
except NotGitRepository:
|
||||||
self.gittle = Gittle.init(path)
|
self.repo = Repo.init(path, mkdir=True)
|
||||||
|
|
||||||
# Dulwich repo
|
|
||||||
self.repo = self.gittle.repo
|
|
||||||
|
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
|
@ -46,20 +40,20 @@ class Wiki(HookMixin):
|
||||||
:param name: Committer name
|
:param name: Committer name
|
||||||
:param email: Committer email
|
:param email: Committer email
|
||||||
:param message: Commit message
|
:param message: Commit message
|
||||||
:param files: list of file names that should be committed
|
:param files: list of file names that will be staged for commit
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# Dulwich and gittle seem to want us to encode ourselves at the moment. see #152
|
|
||||||
if isinstance(name, unicode):
|
if isinstance(name, unicode):
|
||||||
name = name.encode('utf-8')
|
name = name.encode('utf-8')
|
||||||
if isinstance(email, unicode):
|
if isinstance(email, unicode):
|
||||||
email = email.encode('utf-8')
|
email = email.encode('utf-8')
|
||||||
if isinstance(message, unicode):
|
if isinstance(message, unicode):
|
||||||
message = message.encode('utf-8')
|
message = message.encode('utf-8')
|
||||||
return self.gittle.commit(name=name,
|
author = committer = "%s <%s>" % (name, email)
|
||||||
email=email,
|
self.repo.stage(files)
|
||||||
message=message,
|
return self.repo.do_commit(message=message,
|
||||||
files=files)
|
committer=committer,
|
||||||
|
author=author)
|
||||||
|
|
||||||
def get_page(self, name, sha='HEAD'):
|
def get_page(self, name, sha='HEAD'):
|
||||||
"""Get page data, partials, commit info.
|
"""Get page data, partials, commit info.
|
||||||
|
@ -104,7 +98,8 @@ class WikiPage(HookMixin):
|
||||||
if cached:
|
if cached:
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
data = self.wiki.gittle.get_commit_files(self.sha, paths=[self.filename]).get(self.filename).get('data')
|
mode, sha = tree_lookup_path(self.wiki.repo.get_object, self.wiki.repo[self.sha].tree, self.filename)
|
||||||
|
data = self.wiki.repo[sha].data
|
||||||
cache.set(cache_key, data)
|
cache.set(cache_key, data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -257,9 +252,7 @@ class WikiPage(HookMixin):
|
||||||
if not message:
|
if not message:
|
||||||
message = "Deleted %s" % self.name
|
message = "Deleted %s" % self.name
|
||||||
|
|
||||||
# gittle.rm won't actually remove the file, have to do it ourselves
|
|
||||||
os.remove(os.path.join(self.wiki.path, self.filename))
|
os.remove(os.path.join(self.wiki.path, self.filename))
|
||||||
self.wiki.gittle.rm(self.filename)
|
|
||||||
commit = self.wiki.commit(name=username,
|
commit = self.wiki.commit(name=username,
|
||||||
email=email,
|
email=email,
|
||||||
message=message,
|
message=message,
|
||||||
|
@ -278,7 +271,7 @@ class WikiPage(HookMixin):
|
||||||
"""
|
"""
|
||||||
assert self.sha == 'HEAD'
|
assert self.sha == 'HEAD'
|
||||||
old_filename, new_filename = self.filename, cname_to_filename(new_name)
|
old_filename, new_filename = self.filename, cname_to_filename(new_name)
|
||||||
if old_filename not in self.wiki.gittle.index:
|
if old_filename not in self.wiki.repo.open_index():
|
||||||
# old doesn't exist
|
# old doesn't exist
|
||||||
return None
|
return None
|
||||||
elif old_filename == new_filename:
|
elif old_filename == new_filename:
|
||||||
|
@ -293,10 +286,6 @@ class WikiPage(HookMixin):
|
||||||
message = "Moved %s to %s" % (self.name, new_name)
|
message = "Moved %s to %s" % (self.name, new_name)
|
||||||
|
|
||||||
os.rename(os.path.join(self.wiki.path, old_filename), os.path.join(self.wiki.path, new_filename))
|
os.rename(os.path.join(self.wiki.path, old_filename), os.path.join(self.wiki.path, new_filename))
|
||||||
|
|
||||||
self.wiki.gittle.add(new_filename)
|
|
||||||
self.wiki.gittle.rm(old_filename)
|
|
||||||
|
|
||||||
commit = self.wiki.commit(name=username,
|
commit = self.wiki.commit(name=username,
|
||||||
email=email,
|
email=email,
|
||||||
message=message,
|
message=message,
|
||||||
|
@ -311,12 +300,11 @@ class WikiPage(HookMixin):
|
||||||
|
|
||||||
return commit
|
return commit
|
||||||
|
|
||||||
def write(self, content, message=None, create=False, username=None, email=None):
|
def write(self, content, message=None, username=None, email=None):
|
||||||
"""Write page to git repo
|
"""Write page to git repo
|
||||||
|
|
||||||
:param content: Content of page.
|
:param content: Content of page.
|
||||||
:param message: Commit message.
|
:param message: Commit message.
|
||||||
:param create: Perform git add operation?
|
|
||||||
:param username: Commit Name.
|
:param username: Commit Name.
|
||||||
:param email: Commit Email.
|
:param email: Commit Email.
|
||||||
:return: Git commit sha1.
|
:return: Git commit sha1.
|
||||||
|
@ -330,9 +318,6 @@ class WikiPage(HookMixin):
|
||||||
with open(self.wiki.path + "/" + self.filename, 'w') as f:
|
with open(self.wiki.path + "/" + self.filename, 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
if create:
|
|
||||||
self.wiki.gittle.add(self.filename)
|
|
||||||
|
|
||||||
if not message:
|
if not message:
|
||||||
message = "Updated %s" % self.name
|
message = "Updated %s" % self.name
|
||||||
|
|
||||||
|
@ -363,8 +348,7 @@ class WikiPage(HookMixin):
|
||||||
raise PageNotFound('Commit not found')
|
raise PageNotFound('Commit not found')
|
||||||
|
|
||||||
if not message:
|
if not message:
|
||||||
commit_info = gittle.utils.git.commit_info(self.wiki.gittle[commit_sha.encode('latin-1')])
|
message = "Revert '%s' to %s" % (self.name, commit_sha[:7])
|
||||||
message = commit_info['message']
|
|
||||||
|
|
||||||
return self.write(new_page.data, message=message, username=username, email=email)
|
return self.write(new_page.data, message=message, username=username, email=email)
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,6 @@ def page_write(name):
|
||||||
|
|
||||||
sha = g.current_wiki.get_page(cname).write(request.form['content'],
|
sha = g.current_wiki.get_page(cname).write(request.form['content'],
|
||||||
message=request.form['message'],
|
message=request.form['message'],
|
||||||
create=True,
|
|
||||||
username=current_user.username,
|
username=current_user.username,
|
||||||
email=current_user.email)
|
email=current_user.email)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = '0.8.0'
|
__version__ = '0.8.1'
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -35,10 +35,10 @@ setup(name='realms-wiki',
|
||||||
'bcrypt==1.0.2',
|
'bcrypt==1.0.2',
|
||||||
'beautifulsoup4==4.3.2',
|
'beautifulsoup4==4.3.2',
|
||||||
'click==3.3',
|
'click==3.3',
|
||||||
|
'dulwich==0.14.1',
|
||||||
'flask-ldap-login==0.3.0',
|
'flask-ldap-login==0.3.0',
|
||||||
'gevent==1.0.2',
|
'gevent==1.0.2',
|
||||||
'ghdiff==0.4',
|
'ghdiff==0.4',
|
||||||
'gittle==0.5.0',
|
|
||||||
'gunicorn==19.3',
|
'gunicorn==19.3',
|
||||||
'itsdangerous==0.24',
|
'itsdangerous==0.24',
|
||||||
'markdown2==2.3.1',
|
'markdown2==2.3.1',
|
||||||
|
|
Loading…
Reference in a new issue