##// END OF EJS Templates
Removed default contact name...
Removed default contact name changed depracated import of helpers, added manage repo funciton draft. Template updates removed colored logger

File last commit:

r22:31426167 default
r22:31426167 default
Show More
hg.py
118 lines | 3.8 KiB | text/x-python | PythonLexer
Marcin Kuzminski
initial commit.
r0 #!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 from pylons_app.lib.base import BaseController, render
Marcin Kuzminski
Removed default contact name...
r22 from pylons import c, g, session, request
from pylons_app.lib import helpers as h
Marcin Kuzminski
initial commit.
r0 from mako.template import Template
from pprint import pprint
Marcin Kuzminski
added repo creation
r5 import os
from mercurial import ui, hg
from mercurial.error import RepoError
Marcin Kuzminski
added autoconfig loading
r6 from ConfigParser import ConfigParser
Marcin Kuzminski
initial commit.
r0
Marcin Kuzminski
major app speedup moved the wsgi creation to app globals, in order to make it run only once....
r10 log = logging.getLogger(__name__)
Marcin Kuzminski
initial commit.
r0
class HgController(BaseController):
Marcin Kuzminski
Wrapped into mako templates,...
r21
def __before__(self):
c.repos_prefix = 'etelko'
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8
def view(self, *args, **kwargs):
Marcin Kuzminski
Wrapped into mako templates,...
r21 response = g.hgapp(request.environ, self.start_response)
#for mercurial protocols we can't wrap into mako
if request.environ['HTTP_ACCEPT'].find("mercurial") >= 0:
return response
#wrap the murcurial response in a mako template.
template = Template("".join(response),
lookup = request.environ['pylons.pylons']\
.config['pylons.g'].mako_lookup)
return template.render(g = g, c = c, session = session, h = h)
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8
Marcin Kuzminski
Removed default contact name...
r22
def manage_hgrc(self):
pass
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8 def add_repo(self, new_repo):
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 c.staticurl = g.statics
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8 #extra check it can be add since it's the command
if new_repo == 'add':
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 c.msg = 'you basstard ! this repo is a command'
c.new_repo = ''
return render('add.html')
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8
new_repo = new_repo.replace(" ", "_")
new_repo = new_repo.replace("-", "_")
try:
self._create_repo(new_repo)
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 c.new_repo = new_repo
c.msg = 'added repo'
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8 except Exception as e:
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 c.new_repo = 'Exception when adding: %s' % new_repo
c.msg = str(e)
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 return render('add.html')
Marcin Kuzminski
initial commit.
r0
Marcin Kuzminski
added repo creation
r5 def _check_repo(self, repo_name):
Marcin Kuzminski
Added pylons manage script...
r12 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
config_path = os.path.join(p, 'hgwebdir.config')
Marcin Kuzminski
added autoconfig loading
r6
cp = ConfigParser()
cp.read(config_path)
repos_path = cp.get('paths', '/').replace("**", '')
if not repos_path:
raise Exception('Could not read config !')
Marcin Kuzminski
added repo creation
r5 self.repo_path = os.path.join(repos_path, repo_name)
Marcin Kuzminski
initial commit.
r0
Marcin Kuzminski
added repo creation
r5 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):
Marcin Kuzminski
added autoconfig loading
r6 log.info('creating repo %s in %s', repo_name, self.repo_path)
Marcin Kuzminski
added repo creation
r5 cmd = """mkdir %s && hg init %s""" \
% (self.repo_path, self.repo_path)
os.popen(cmd)
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8 #def _make_app():
# #for single a repo
# #return hgweb("/path/to/repo", "Name")
# repos = "hgwebdir.config"
# return hgwebdir(repos)
#
Marcin Kuzminski
added repo creation
r5
Marcin Kuzminski
Changed to webapp, removed get from routes,
r8 # def view(self, environ, start_response):
# #the following is only needed when using hgwebdir
# app = _make_app()
# #return wsgi_app(environ, start_response)
# response = app(request.environ, self.start_response)
#
# if environ['PATH_INFO'].find("static") != -1:
# return response
# else:
# #wrap the murcurial response in a mako template.
# template = Template("".join(response),
# lookup = environ['pylons.pylons']\
# .config['pylons.g'].mako_lookup)
#
# return template.render(g = g, c = c, session = session, h = h)