Files
@ a86c8de926b4
Branch filter:
Location: kallithea/pylons_app/controllers/admin.py - annotation
a86c8de926b4
4.4 KiB
text/x-python
some fixes in graph tab. Little fixes in files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b d924b931b488 a886f5eba757 a886f5eba757 a886f5eba757 4df4c0eac619 4df4c0eac619 6f524697f79d 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 8b06c420491d 25e516447a33 a886f5eba757 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 9db7782727b3 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 4df4c0eac619 4df4c0eac619 6f524697f79d 6f524697f79d 6f524697f79d 6f524697f79d 6f524697f79d 9fe23fdab9e9 9fe23fdab9e9 9fe23fdab9e9 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b d924b931b488 d924b931b488 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b | import logging
from pylons import request, response, session, tmpl_context as c, url, app_globals as g
from pylons.controllers.util import abort, redirect
from pylons_app.lib.base import BaseController, render
import os
from mercurial import ui, hg
from mercurial.error import RepoError
from ConfigParser import ConfigParser
from pylons_app.lib import auth
from pylons_app.model.forms import LoginForm
import formencode
import formencode.htmlfill as htmlfill
from pylons_app.model import meta
from pylons_app.model.db import Users, UserLogs
from webhelpers.paginate import Page
log = logging.getLogger(__name__)
class AdminController(BaseController):
def __before__(self):
c.admin_user = session.get('admin_user', False)
c.admin_username = session.get('admin_username')
def index(self):
# Return a rendered template
if request.POST:
#import Login Form validator class
login_form = LoginForm()
try:
c.form_result = login_form.to_python(dict(request.params))
if auth.admin_auth(c.form_result['username'], c.form_result['password']):
session['admin_user'] = True
session['admin_username'] = c.form_result['username']
session.save()
return redirect(url('admin_home'))
else:
raise formencode.Invalid('Login Error', None, None,
error_dict={'username':'invalid login',
'password':'invalid password'})
except formencode.Invalid, error:
c.form_result = error.value
c.form_errors = error.error_dict or {}
html = render('/admin.html')
return htmlfill.render(
html,
defaults=c.form_result,
encoding="UTF-8"
)
if c.admin_user:
sa = meta.Session
users_log = sa.query(UserLogs)\
.order_by(UserLogs.action_date.desc())
p = int(request.params.get('page', 1))
c.users_log = Page(users_log, page=p, items_per_page=10)
c.log_data = render('admin_log.html')
if request.params.get('partial'):
return c.log_data
return render('/admin.html')
def hgrc(self, dirname):
filename = os.path.join(dirname, '.hg', 'hgrc')
return filename
def add_repo(self, new_repo):
#extra check it can be add since it's the command
if new_repo == '_admin':
c.msg = 'DENIED'
c.new_repo = ''
return render('add.html')
new_repo = new_repo.replace(" ", "_")
new_repo = new_repo.replace("-", "_")
try:
self._create_repo(new_repo)
c.new_repo = new_repo
c.msg = 'added repo'
except Exception as e:
c.new_repo = 'Exception when adding: %s' % new_repo
c.msg = str(e)
return render('add.html')
def _check_repo(self, repo_name):
p = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
config_path = os.path.join(p, 'hgwebdir.config')
cp = ConfigParser()
cp.read(config_path)
repos_path = cp.get('paths', '/').replace("**", '')
if not repos_path:
raise Exception('Could not read config !')
self.repo_path = os.path.join(repos_path, repo_name)
try:
r = hg.repository(ui.ui(), self.repo_path)
hg.verify(r)
#here we hnow that repo exists it was verified
log.info('%s repo is already created', repo_name)
raise Exception('Repo exists')
except RepoError:
log.info('%s repo is free for creation', repo_name)
#it means that there is no valid repo there...
return True
def _create_repo(self, repo_name):
if repo_name in [None, '', 'add']:
raise Exception('undefined repo_name of repo')
if self._check_repo(repo_name):
log.info('creating repo %s in %s', repo_name, self.repo_path)
cmd = """mkdir %s && hg init %s""" \
% (self.repo_path, self.repo_path)
os.popen(cmd)
|