Changeset - 0e87466a117e
[Not reviewed]
default
1 4 1
Marcin Kuzminski - 15 years ago 2010-07-01 00:57:45
marcin@python-works.com
updated installation instruction, made more user friendly way of creating all needed configs. All is done now from paster setup-app
5 files changed with 56 insertions and 24 deletions:
0 comments (0 inline, 0 general)
.hgignore
Show inline comments
 

	
 
syntax: regexp
 
^data$
 
syntax: regexp
 
^\.settings$
 
syntax: regexp
 
^\.project$
 
syntax: regexp
 
^\.pydevproject$
 
syntax: regexp
 
^hg_app\.db$
 
\ No newline at end of file
 
^hg_app\.db$
 
syntax: regexp
 
^repositories\.config$
 
\ No newline at end of file
README.rst
Show inline comments
 
@@ -19,39 +19,38 @@ Fully customizable, with authentication,
 
  file-system operations
 
- added cache with invalidation on push/repo managment for high performance and
 
  always upto date data.
 
- rss /atom feed customizable
 
- future support for git
 
- based on pylons 1.0 / sqlalchemy 0.6
 

	
 
**Incoming**
 

	
 
- code review based on hg-review (when it's stable)
 
- git support (when vcs can handle it)
 
- other cools stuff that i can figure out
 

	
 
.. note::
 
   This software is still in beta mode. I don't guarantee that it'll work.
 
   
 

	
 
-------------
 
Installation
 
-------------
 
.. note::
 
   I recomend to install tip version of vcs while the app is in beta mode.
 
   
 
   
 
- create new virtualenv and activate it
 
- create new virtualenv and activate it - highly recommend that you use separate
 
  virtual-env for whole application
 
- download hg app from default (not demo) branch from bitbucket and run 
 
  'python setup.py install' this will install all required dependencies needed
 
- goto pylons_app/lib and run python db_manage.py it should create all 
 
  needed tables and an admin account. You can play with this file if you wish to
 
  use different db than sqlite 
 
- edit file repositories.config and change the [paths] where you keep your
 
  mercurial repositories, remember about permissions for accessing this dir by
 
  hg app.
 
- run paster serve development.ini 
 
- run paster setup-app production.ini it should create all needed tables 
 
  and an admin account. Also it will create repositories.config for mercurial 
 
  commands, remember that the given path for mercurial repositories must be write
 
  accessible for the application
 
- run paster serve development.ini - or you can use manage-hg_app script.
 
  the app should be available at the 127.0.0.1:5000
 
- use admin account you created to login.
 
- default permissions on each repository is read, and owner is admin. So remember
 
  to update those.
 
     
 
\ No newline at end of file
pylons_app/config/repositories.config_tmpl
Show inline comments
 
file renamed from repositories.config to pylons_app/config/repositories.config_tmpl
 
[hooks]
 
#to do push with autoupdate
 
changegroup = hg update >&2
 

	
 
[web]
 
#for http requests push ssl to false
 
push_ssl = false
 
allow_archive = gz zip bz2
 
allow_push = *
 
baseurl = /
 

	
 
[paths]
 
#this path should point to mercurial repositories remeber about '*' at the end
 
/ = /home/marcink/python_workspace/*
 
/ = %(repo_location)s
pylons_app/lib/db_manage.py
Show inline comments
 
@@ -6,138 +6,129 @@
 
# This program is free software; you can redistribute it and/or
 
# modify it under the terms of the GNU General Public License
 
# as published by the Free Software Foundation; version 2
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 

	
 
"""
 
Created on April 10, 2010
 
database managment and creation for hg app
 
@author: marcink
 
"""
 

	
 
from os.path import dirname as dn, join as jn
 
import os
 
import sys
 
import uuid
 
ROOT = dn(dn(dn(os.path.realpath(__file__))))
 
sys.path.append(ROOT)
 

	
 
from pylons_app.lib.auth import get_crypt_password
 
from pylons_app.model import init_model
 
from pylons_app.model.db import User, Permission
 
from pylons_app.model.meta import Session, Base
 
from sqlalchemy.engine import create_engine
 
import logging
 

	
 
log = logging.getLogger('db manage')
 
log.setLevel(logging.DEBUG)
 
console_handler = logging.StreamHandler()
 
console_handler.setFormatter(logging.Formatter("%(asctime)s.%(msecs)03d" 
 
                                    " %(levelname)-5.5s [%(name)s] %(message)s"))
 
                                  " %(levelname)-5.5s [%(name)s] %(message)s"))
 
log.addHandler(console_handler)
 

	
 
class DbManage(object):
 
    def __init__(self, log_sql):
 
        self.dbname = 'hg_app.db'
 
        dburi = 'sqlite:////%s' % jn(ROOT, self.dbname)
 
        engine = create_engine(dburi, echo=log_sql) 
 
        init_model(engine)
 
        self.sa = Session()
 
        self.db_exists = False
 
    
 
    def check_for_db(self, override):
 
        log.info('checking for exisiting db')
 
        if os.path.isfile(jn(ROOT, self.dbname)):
 
            self.db_exists = True
 
            log.info('database exisist')
 
            if not override:
 
                raise Exception('database already exists')
 

	
 
    def create_tables(self, override=False):
 
        """
 
        Create a auth database
 
        """
 
        self.check_for_db(override)
 
        if override:
 
            log.info("database exisist and it's going to be destroyed")
 
            if self.db_exists:
 
                os.remove(jn(ROOT, self.dbname))
 
        Base.metadata.create_all(checkfirst=override)
 
        log.info('Created tables for %s', self.dbname)
 
    
 
    def admin_prompt(self):
 
        import getpass
 
        username = raw_input('Specify admin username:')
 
        password = getpass.getpass('Specify admin password:')
 
        self.create_user(username, password, True)
 
        
 
    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 = 'default'
 
        def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
 
        def_user.name = 'default'
 
        def_user.lastname = 'default'
 
        def_user.email = 'default@default'
 
        def_user.email = 'default@default.com'
 
        def_user.admin = False
 
        def_user.active = False
 
        
 
        self.sa.add(def_user)
 
        
 
        log.info('creating administrator user %s', username)
 
        new_user = User()
 
        new_user.username = username
 
        new_user.password = get_crypt_password(password)
 
        new_user.name = 'Hg'
 
        new_user.lastname = 'Admin'
 
        new_user.email = 'admin@localhost'
 
        new_user.admin = admin
 
        new_user.active = True
 
        
 
        try:
 
            self.sa.add(new_user)
 
            self.sa.commit()
 
        except:
 
            self.sa.rollback()
 
            raise
 
    
 
    def create_permissions(self):
 
        #module.(access|create|change|delete)_[name]
 
        #module.(read|write|owner)
 
        perms = [('repository.none', 'Repository no access'),
 
                 ('repository.read', 'Repository read access'),
 
                 ('repository.write', 'Repository write access'),
 
                 ('repository.admin', 'Repository admin access'),
 
                 ('hg.admin', 'Hg Administrator'),
 
                 ]
 
        
 
        for p in perms:
 
            new_perm = Permission()
 
            new_perm.permission_name = p[0]
 
            new_perm.permission_longname = p[1]
 
            try:
 
                self.sa.add(new_perm)
 
                self.sa.commit()
 
            except:
 
                self.sa.rollback()
 
                raise
 
        
 
        
 
        
 
if __name__ == '__main__':
 
    dbmanage = DbManage(log_sql=True)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.admin_prompt()
 
    dbmanage.create_permissions()  
 

	
 

	
pylons_app/websetup.py
Show inline comments
 
"""Setup the pylons_app application"""
 

	
 
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 logging
 
from pylons_app.config.environment import load_environment
 
import os
 
import sys
 

	
 
log = logging.getLogger(__name__)
 

	
 
ROOT = dn(dn(os.path.realpath(__file__)))
 
sys.path.append(ROOT)
 

	
 

	
 
def setup_repository():
 
    log.info('Seting up repositories.config')
 
    fname = 'repositories.config'
 
    
 
    try:
 
        tmpl = open(jn(ROOT, 'pylons_app', 'config', 'repositories.config_tmpl')).read()
 
    except IOError:
 
        raise
 
    
 
    path = raw_input('Specify valid full path to your repositories'
 
                    ' you can change this later in repositories.config file:')
 
    
 
    if not os.path.isdir(path):
 
        log.error('You entered wrong path')
 
        sys.exit()
 
    
 
    
 
    path = jn(path, '*') 
 
    dest_path = jn(ROOT, fname)
 
    f = open(dest_path, 'wb')
 
    f.write(tmpl % {'repo_location':path})
 
    f.close()
 
    log.info('created repositories.config in %s', dest_path)
 
        
 

	
 
def setup_app(command, conf, vars):
 
    """Place any commands to setup pylons_app here"""
 
    setup_repository()
 
    dbmanage = DbManage(log_sql=True)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.admin_prompt()
 
    dbmanage.create_permissions()
 
    load_environment(conf.global_conf, conf.local_conf)
 

	
0 comments (0 inline, 0 general)