Changeset - 7c978511c951
pylons_app/config/environment.py
Show inline comments
 
@@ -52,7 +52,7 @@ def load_environment(global_conf, app_co
 
    
 
    #MULTIPLE DB configs
 
    # Setup the SQLAlchemy database engine
 
    if config['debug']:
 
    if config['debug'] and os.path.split(config['__file__'])[-1] != 'tests.ini':
 
        #use query time debugging.
 
        from pylons_app.lib.timerproxy import TimerProxy
 
        sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.',
pylons_app/config/routing.py
Show inline comments
 
@@ -71,18 +71,17 @@ def make_map(config):
 
    map.resource('user', 'users', controller='admin/users', path_prefix='/_admin')
 
    map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin')
 
    
 
    #map.resource('setting', 'settings', controller='admin/settings', path_prefix='/_admin', name_prefix='admin_')
 
    #REST SETTINGS MAP
 
    with map.submapper(path_prefix='/_admin', controller='admin/settings') as m:
 
        m.connect("admin_settings", "/settings",
 
             action="create", conditions=dict(method=["POST"]))
 
        m.connect("admin_settings", "/settings",
 
             action="index", conditions=dict(method=["GET"]))
 
        m.connect("admin_formatted_settings", "/settings.{format}",
 
        m.connect("formatted_admin_settings", "/settings.{format}",
 
             action="index", conditions=dict(method=["GET"]))
 
        m.connect("admin_new_setting", "/settings/new",
 
             action="new", conditions=dict(method=["GET"]))
 
        m.connect("admin_formatted_new_setting", "/settings/new.{format}",
 
        m.connect("formatted_admin_new_setting", "/settings/new.{format}",
 
             action="new", conditions=dict(method=["GET"]))
 
        m.connect("/settings/{setting_id}",
 
             action="update", conditions=dict(method=["PUT"]))
 
@@ -90,11 +89,11 @@ def make_map(config):
 
             action="delete", conditions=dict(method=["DELETE"]))
 
        m.connect("admin_edit_setting", "/settings/{setting_id}/edit",
 
             action="edit", conditions=dict(method=["GET"]))
 
        m.connect("admin_formatted_edit_setting", "/settings/{setting_id}.{format}/edit",
 
        m.connect("formatted_admin_edit_setting", "/settings/{setting_id}.{format}/edit",
 
             action="edit", conditions=dict(method=["GET"]))
 
        m.connect("admin_setting", "/settings/{setting_id}",
 
             action="show", conditions=dict(method=["GET"]))
 
        m.connect("admin_formatted_setting", "/settings/{setting_id}.{format}",
 
        m.connect("formatted_admin_setting", "/settings/{setting_id}.{format}",
 
             action="show", conditions=dict(method=["GET"]))
 
        m.connect("admin_settings_my_account", "/my_account",
 
             action="my_account", conditions=dict(method=["GET"]))
pylons_app/controllers/login.py
Show inline comments
 
@@ -30,9 +30,7 @@ from pylons_app.lib.auth import AuthUser
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.model.forms import LoginForm, RegisterForm
 
from pylons_app.model.user_model import UserModel
 
from sqlalchemy.exc import OperationalError
 
import formencode
 
import datetime
 
import logging
 

	
 
log = logging.getLogger(__name__)
pylons_app/lib/db_manage.py
Show inline comments
 
@@ -43,8 +43,9 @@ import logging
 
log = logging.getLogger(__name__)
 

	
 
class DbManage(object):
 
    def __init__(self, log_sql):
 
        self.dbname = 'hg_app.db'
 
    def __init__(self, log_sql, dbname,tests=False):
 
        self.dbname = dbname
 
        self.tests = tests
 
        dburi = 'sqlite:////%s' % jn(ROOT, self.dbname)
 
        engine = create_engine(dburi, echo=log_sql) 
 
        init_model(engine)
 
@@ -66,6 +67,9 @@ class DbManage(object):
 
        self.check_for_db(override)
 
        if override:
 
            log.info("database exisist and it's going to be destroyed")
 
            if self.tests:
 
                destroy=True
 
            else:
 
            destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
 
            if not destroy:
 
                sys.exit()
 
@@ -76,19 +80,29 @@ class DbManage(object):
 
        log.info('Created tables for %s', self.dbname)
 
    
 
    def admin_prompt(self):
 
        if not self.tests:
 
        import getpass
 
        username = raw_input('Specify admin username:')
 
        password = getpass.getpass('Specify admin password:')
 
        self.create_user(username, password, True)
 
        else:
 
            log.info('creating admin and regular test users')
 
            self.create_user('test_admin', 'test', True)
 
            self.create_user('test_regular', 'test', False)
 
    
 
    def config_prompt(self):
 
        
 
    
 
    def config_prompt(self,test_repo_path=''):
 
        log.info('Setting up repositories config')
 
        
 
        if not self.tests and not test_repo_path:
 
        path = raw_input('Specify valid full path to your repositories'
 
                        ' you can change this later in application settings:')
 
        else:
 
            path = test_repo_path
 
        
 
        if not os.path.isdir(path):
 
            log.error('You entered wrong path')
 
            log.error('You entered wrong path: %s',path)
 
            sys.exit()
 
        
 
        hooks1 = HgAppUi()
 
@@ -153,18 +167,6 @@ class DbManage(object):
 
        log.info('created ui config')
 
                    
 
    def create_user(self, username, password, admin=False):
 
        
 
        log.info('creating default user')
 
        #create default user for handling default permissions.
 
        def_user = User()
 
        def_user.username = 'default'
 
        def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
 
        def_user.name = 'default'
 
        def_user.lastname = 'default'
 
        def_user.email = 'default@default.com'
 
        def_user.admin = False
 
        def_user.active = False
 
        
 
        log.info('creating administrator user %s', username)
 
        new_user = User()
 
        new_user.username = username
 
@@ -176,8 +178,25 @@ class DbManage(object):
 
        new_user.active = True
 
        
 
        try:
 
            self.sa.add(new_user)
 
            self.sa.commit()
 
        except:
 
            self.sa.rollback()
 
            raise
 

	
 
    def create_default_user(self):
 
        log.info('creating default user')
 
        #create default user for handling default permissions.
 
        def_user = User()
 
        def_user.username = 'default'
 
        def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
 
        def_user.name = 'default'
 
        def_user.lastname = 'default'
 
        def_user.email = 'default@default.com'
 
        def_user.admin = False
 
        def_user.active = False
 
        try:
 
            self.sa.add(def_user)
 
            self.sa.add(new_user)
 
            self.sa.commit()
 
        except:
 
            self.sa.rollback()
pylons_app/model/db.py
Show inline comments
 
@@ -26,7 +26,7 @@ class HgAppUi(Base):
 
    
 
class User(Base): 
 
    __tablename__ = 'users'
 
    __table_args__ = {'useexisting':True}
 
    __table_args__ = (UniqueConstraint('username'), {'useexisting':True})
 
    user_id = Column("user_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True)
 
    username = Column("username", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 
    password = Column("password", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
pylons_app/tests/__init__.py
Show inline comments
 
@@ -14,23 +14,23 @@ from paste.script.appinstall import Setu
 
from pylons import config, url
 
from routes.util import URLGenerator
 
from webtest import TestApp
 
import os
 

	
 
import pylons.test
 

	
 
__all__ = ['environ', 'url', 'TestController']
 

	
 
# Invoke websetup with the current config file
 
SetupCommand('setup-app').run([config['__file__']])
 
SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
 

	
 
environ = {}
 

	
 
class TestController(TestCase):
 

	
 
    def __init__(self, *args, **kwargs):
 
        if pylons.test.pylonsapp:
 
            wsgiapp = pylons.test.pylonsapp
 
        else:
 
            wsgiapp = loadapp('config:%s' % config['__file__'])
 
        config = wsgiapp.config
 
        self.app = TestApp(wsgiapp)
 
        url._push_object(URLGenerator(config['routes.map'], environ))
 
        TestCase.__init__(self, *args, **kwargs)
 

	
pylons_app/tests/functional/test_admin.py
Show inline comments
 
@@ -3,5 +3,5 @@ from pylons_app.tests import *
 
class TestAdminController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='admin', action='index'))
 
        response = self.app.get(url(controller='admin/admin', action='index'))
 
        # Test response...
pylons_app/tests/functional/test_admin_settings.py
Show inline comments
 
@@ -19,25 +19,25 @@ class TestSettingsController(TestControl
 
        response = self.app.get(url('formatted_admin_new_setting', format='xml'))
 

	
 
    def test_update(self):
 
        response = self.app.put(url('admin_setting', id=1))
 
        response = self.app.put(url('admin_setting', setting_id=1))
 

	
 
    def test_update_browser_fakeout(self):
 
        response = self.app.post(url('admin_setting', id=1), params=dict(_method='put'))
 
        response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='put'))
 

	
 
    def test_delete(self):
 
        response = self.app.delete(url('admin_setting', id=1))
 
        response = self.app.delete(url('admin_setting', setting_id=1))
 

	
 
    def test_delete_browser_fakeout(self):
 
        response = self.app.post(url('admin_setting', id=1), params=dict(_method='delete'))
 
        response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='delete'))
 

	
 
    def test_show(self):
 
        response = self.app.get(url('admin_setting', id=1))
 
        response = self.app.get(url('admin_setting', setting_id=1))
 

	
 
    def test_show_as_xml(self):
 
        response = self.app.get(url('formatted_admin_setting', id=1, format='xml'))
 
        response = self.app.get(url('formatted_admin_setting', setting_id=1, format='xml'))
 

	
 
    def test_edit(self):
 
        response = self.app.get(url('admin_edit_setting', id=1))
 
        response = self.app.get(url('admin_edit_setting', setting_id=1))
 

	
 
    def test_edit_as_xml(self):
 
        response = self.app.get(url('formatted_admin_edit_setting', id=1, format='xml'))
 
        response = self.app.get(url('formatted_admin_edit_setting', setting_id=1, format='xml'))
pylons_app/tests/functional/test_admin_settings_hg.py
Show inline comments
 
deleted file
pylons_app/tests/functional/test_branches.py
Show inline comments
 
@@ -3,5 +3,5 @@ from pylons_app.tests import *
 
class TestBranchesController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='branches', action='index'))
 
        response = self.app.get(url(controller='branches', action='index',repo_name='vcs_test'))
 
        # Test response...
pylons_app/tests/functional/test_changelog.py
Show inline comments
 
@@ -3,5 +3,5 @@ from pylons_app.tests import *
 
class TestChangelogController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='changelog', action='index'))
 
        response = self.app.get(url(controller='changelog', action='index',repo_name='vcs_test'))
 
        # Test response...
pylons_app/tests/functional/test_changeset.py
Show inline comments
 
@@ -3,5 +3,6 @@ from pylons_app.tests import *
 
class TestChangesetController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='changeset', action='index'))
 
        response = self.app.get(url(controller='changeset', action='index',
 
                                    repo_name='vcs_test',revision='tip'))
 
        # Test response...
pylons_app/tests/functional/test_feed.py
Show inline comments
 
@@ -2,6 +2,12 @@ from pylons_app.tests import *
 

	
 
class TestFeedController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='feed', action='index'))
 
    def test_rss(self):
 
        response = self.app.get(url(controller='feed', action='rss',
 
                                    repo_name='vcs_test'))
 
        # Test response...
 

	
 
    def test_atom(self):
 
        response = self.app.get(url(controller='feed', action='atom',
 
                                    repo_name='vcs_test'))
 
        # Test response...
 
\ No newline at end of file
pylons_app/tests/functional/test_files.py
Show inline comments
 
@@ -3,5 +3,8 @@ from pylons_app.tests import *
 
class TestFilesController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='files', action='index'))
 
        response = self.app.get(url(controller='files', action='index',
 
                                    repo_name='vcs_test',
 
                                    revision='tip',
 
                                    f_path='/'))
 
        # Test response...
pylons_app/tests/functional/test_repos.py
Show inline comments
 
@@ -19,25 +19,25 @@ class TestReposController(TestController
 
        response = self.app.get(url('formatted_new_repo', format='xml'))
 

	
 
    def test_update(self):
 
        response = self.app.put(url('repo', id=1))
 
        response = self.app.put(url('repo', repo_name='vcs_test'))
 

	
 
    def test_update_browser_fakeout(self):
 
        response = self.app.post(url('repo', id=1), params=dict(_method='put'))
 
        response = self.app.post(url('repo', repo_name='vcs_test'), params=dict(_method='put'))
 

	
 
    def test_delete(self):
 
        response = self.app.delete(url('repo', id=1))
 
        response = self.app.delete(url('repo', repo_name='vcs_test'))
 

	
 
    def test_delete_browser_fakeout(self):
 
        response = self.app.post(url('repo', id=1), params=dict(_method='delete'))
 
        response = self.app.post(url('repo', repo_name='vcs_test'), params=dict(_method='delete'))
 

	
 
    def test_show(self):
 
        response = self.app.get(url('repo', id=1))
 
        response = self.app.get(url('repo', repo_name='vcs_test'))
 

	
 
    def test_show_as_xml(self):
 
        response = self.app.get(url('formatted_repo', id=1, format='xml'))
 
        response = self.app.get(url('formatted_repo', repo_name='vcs_test', format='xml'))
 

	
 
    def test_edit(self):
 
        response = self.app.get(url('edit_repo', id=1))
 
        response = self.app.get(url('edit_repo', repo_name='vcs_test'))
 

	
 
    def test_edit_as_xml(self):
 
        response = self.app.get(url('formatted_edit_repo', id=1, format='xml'))
 
        response = self.app.get(url('formatted_edit_repo', repo_name='vcs_test', format='xml'))
pylons_app/tests/functional/test_settings.py
Show inline comments
 
@@ -3,5 +3,6 @@ from pylons_app.tests import *
 
class TestSettingsController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='settings', action='index'))
 
        response = self.app.get(url(controller='settings', action='index',
 
                                    repo_name='vcs_test'))
 
        # Test response...
pylons_app/tests/functional/test_shortlog.py
Show inline comments
 
@@ -3,5 +3,5 @@ from pylons_app.tests import *
 
class TestShortlogController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='shortlog', action='index'))
 
        response = self.app.get(url(controller='shortlog', action='index',repo_name='vcs_test'))
 
        # Test response...
pylons_app/tests/functional/test_summary.py
Show inline comments
 
@@ -3,5 +3,5 @@ from pylons_app.tests import *
 
class TestSummaryController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='summary', action='index'))
 
        response = self.app.get(url(controller='summary', action='index',repo_name='vcs_test'))
 
        # Test response...
pylons_app/tests/functional/test_tags.py
Show inline comments
 
@@ -3,5 +3,5 @@ from pylons_app.tests import *
 
class TestTagsController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='tags', action='index'))
 
        response = self.app.get(url(controller='tags', action='index',repo_name='vcs_test'))
 
        # Test response...
pylons_app/websetup.py
Show inline comments
 
@@ -3,10 +3,12 @@
 
from os.path import dirname as dn, join as jn
 
from pylons_app.config.environment import load_environment
 
from pylons_app.lib.db_manage import DbManage
 
import datetime
 
from time import mktime
 
import logging
 
import os
 
import sys
 

	
 
import shutil
 
log = logging.getLogger(__name__)
 

	
 
ROOT = dn(dn(os.path.realpath(__file__)))
 
@@ -14,9 +16,27 @@ sys.path.append(ROOT)
 

	
 
def setup_app(command, conf, vars):
 
    """Place any commands to setup pylons_app here"""
 
    dbmanage = DbManage(log_sql=True)
 
    log_sql = True
 
    tests = False
 
    
 
    dbname = os.path.split(conf['sqlalchemy.db1.url'])[-1]
 
    filename = os.path.split(conf.filename)[-1]
 
    
 
    if filename == 'tests.ini':
 
        uniq_suffix = str(int(mktime(datetime.datetime.now().timetuple())))
 
        REPO_TEST_PATH = '/tmp/hg_app_test_%s' % uniq_suffix
 
        
 
        if not os.path.isdir(REPO_TEST_PATH):
 
            os.mkdir(REPO_TEST_PATH)
 
            from_ = '/home/marcink/workspace-python/vcs'
 
            shutil.copytree(from_, os.path.join(REPO_TEST_PATH,'vcs_test'))
 
            
 
        tests = True    
 
    
 
    dbmanage = DbManage(log_sql, dbname, tests)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.config_prompt()
 
    dbmanage.config_prompt(REPO_TEST_PATH)
 
    dbmanage.create_default_user()
 
    dbmanage.admin_prompt()
 
    dbmanage.create_permissions()
 
    dbmanage.populate_default_permissions()
setup.cfg
Show inline comments
 
@@ -6,7 +6,10 @@ tag_svn_revision = true
 
find_links = http://www.pylonshq.com/download/
 

	
 
[nosetests]
 
with-pylons = development.ini
 
verbose=True
 
verbosity=2
 
with-pylons=tests.ini
 
detailed-errors=1
 

	
 
# Babel configuration
 
[compile_catalog]
tests.ini
Show inline comments
 
new file 100644
 
################################################################################
 
################################################################################
 
# pylons_app - Pylons environment configuration                                #
 
#                                                                              # 
 
# The %(here)s variable will be replaced with the parent directory of this file#
 
################################################################################
 

	
 
[DEFAULT]
 
debug = true
 
############################################
 
## Uncomment and replace with the address ##
 
## which should receive any error reports ##
 
############################################
 
#email_to = admin@localhost
 
#smtp_server = mail.server.com
 
#error_email_from = paste_error@localhost
 
#smtp_username = 
 
#smtp_password = 
 
#error_message = 'mercurial crash !'
 

	
 
[server:main]
 
##nr of threads to spawn
 
threadpool_workers = 5
 

	
 
##max request before
 
threadpool_max_requests = 2
 

	
 
##option to use threads of process
 
use_threadpool = true
 

	
 
use = egg:Paste#http
 
host = 127.0.0.1
 
port = 5000
 

	
 
[app:main]
 
use = egg:pylons_app
 
full_stack = true
 
static_files = true
 
lang=en
 
cache_dir = %(here)s/data
 

	
 
####################################
 
###         BEAKER CACHE        ####
 
####################################
 
beaker.cache.data_dir=/%(here)s/data/cache/data
 
beaker.cache.lock_dir=/%(here)s/data/cache/lock
 
beaker.cache.regions=super_short_term,short_term,long_term
 
beaker.cache.long_term.type=memory
 
beaker.cache.long_term.expire=36000
 
beaker.cache.short_term.type=memory
 
beaker.cache.short_term.expire=60
 
beaker.cache.super_short_term.type=memory
 
beaker.cache.super_short_term.expire=10
 

	
 
####################################
 
###       BEAKER SESSION        ####
 
####################################
 
## Type of storage used for the session, current types are 
 
## “dbm”, “file”, “memcached”, “database”, and “memory”. 
 
## The storage uses the Container API 
 
##that is also used by the cache system.
 
beaker.session.type = file
 

	
 
beaker.session.key = hg-app
 
beaker.session.secret = g654dcno0-9873jhgfreyu
 
beaker.session.timeout = 36000
 

	
 
##auto save the session to not to use .save()
 
beaker.session.auto = False
 

	
 
##true exire at browser close
 
#beaker.session.cookie_expires = 3600
 

	
 
    
 
################################################################################
 
## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*  ##
 
## Debug mode will enable the interactive debugging tool, allowing ANYONE to  ##
 
## execute malicious code after an exception is raised.                       ##
 
################################################################################
 
#set debug = false
 

	
 
##################################
 
###       LOGVIEW CONFIG       ###
 
##################################
 
logview.sqlalchemy = #faa
 
logview.pylons.templating = #bfb
 
logview.pylons.util = #eee
 

	
 
#########################################################
 
### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
 
#########################################################
 
sqlalchemy.db1.url = sqlite:///%(here)s/test.db
 
#sqlalchemy.db1.echo = False
 
#sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.convert_unicode = true
 

	
 
################################
 
### LOGGING CONFIGURATION   ####
 
################################
 
[loggers]
 
keys = root, routes, pylons_app, sqlalchemy
 

	
 
[handlers]
 
keys = console
 

	
 
[formatters]
 
keys = generic,color_formatter
 

	
 
#############
 
## LOGGERS ##
 
#############
 
[logger_root]
 
level = ERROR
 
handlers = console
 

	
 
[logger_routes]
 
level = ERROR
 
handlers = console
 
qualname = routes.middleware
 
# "level = DEBUG" logs the route matched and routing variables.
 

	
 
[logger_pylons_app]
 
level = ERROR
 
handlers = console
 
qualname = pylons_app
 
propagate = 0
 

	
 
[logger_sqlalchemy]
 
level = ERROR
 
handlers = console
 
qualname = sqlalchemy.engine
 
propagate = 0
 

	
 
##############
 
## HANDLERS ##
 
##############
 

	
 
[handler_console]
 
class = StreamHandler
 
args = (sys.stderr,)
 
level = NOTSET
 
formatter = color_formatter
 

	
 
################
 
## FORMATTERS ##
 
################
 

	
 
[formatter_generic]
 
format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
 
datefmt = %Y-%m-%d %H:%M:%S
 

	
 
[formatter_color_formatter]
 
class=pylons_app.lib.colored_formatter.ColorFormatter
 
format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
 
datefmt = %Y-%m-%d %H:%M:%S
 
\ No newline at end of file
0 comments (0 inline, 0 general)