changeset 2290:533a126dc9ab

merged with beta
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 17 May 2012 00:55:35 +0200
parents b8d5a5c9f66d (current diff) 5893414dea91 (diff)
children 0ba23ea7912a
files docs/changelog.rst docs/setup.rst rhodecode/lib/db_manage.py rhodecode/websetup.py setup.py
diffstat 8 files changed, 129 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/docs/changelog.rst	Wed May 16 01:25:00 2012 +0200
+++ b/docs/changelog.rst	Thu May 17 00:55:35 2012 +0200
@@ -4,13 +4,15 @@
 Changelog
 =========
 
-1.3.6 (**2012-05-16**)
+1.3.6 (**2012-05-17**)
 ----------------------
 
 news
 ++++
 
 - chinese traditional translation
+- changed setup-app into setup-rhodecode and added arguments for auto-setup 
+  mode that doesn't need user interaction 
 
 fixes
 +++++
--- a/docs/setup.rst	Wed May 16 01:25:00 2012 +0200
+++ b/docs/setup.rst	Thu May 17 00:55:35 2012 +0200
@@ -26,19 +26,20 @@
 postgresql, sqlite and mysql databases. Create the database by running
 the following command::
 
-    paster setup-app production.ini
+    paster setup-rhodecode production.ini
 
 This will prompt you for a "root" path. This "root" path is the location where
 RhodeCode will store all of its repositories on the current machine. After
-entering this "root" path ``setup-app`` will also prompt you for a username 
-and password for the initial admin account which ``setup-app`` sets up for you.
+entering this "root" path ``setup-rhodecode`` will also prompt you for a username 
+and password for the initial admin account which ``setup-rhodecode`` sets 
+up for you.
 
-- The ``setup-app`` command will create all of the needed tables and an admin
-  account. When choosing a root path you can either use a new empty location, 
-  or a location which already contains existing repositories. If you choose a 
-  location which contains existing repositories RhodeCode will simply add all 
-  of the repositories at the chosen location to it's database. (Note: make 
-  sure you specify the correct path to the root).
+- The ``setup-rhodecode`` command will create all of the needed tables and an 
+  admin account. When choosing a root path you can either use a new empty 
+  location, or a location which already contains existing repositories. If you
+  choose a location which contains existing repositories RhodeCode will simply 
+  add all of the repositories at the chosen location to it's database. 
+  (Note: make sure you specify the correct path to the root).
 - Note: the given path for mercurial_ repositories **must** be write accessible
   for the application. It's very important since the RhodeCode web interface 
   will work without write access, but when trying to do a push it will 
@@ -51,8 +52,8 @@
 - This command runs the RhodeCode server. The web app should be available at the 
   127.0.0.1:5000. This ip and port is configurable via the production.ini 
   file created in previous step
-- Use the admin account you created above when running ``setup-app`` to login 
-  to the web app.
+- Use the admin account you created above when running ``setup-rhodecode`` 
+  to login to the web app.
 - The default permissions on each repository is read, and the owner is admin. 
   Remember to update these if needed.
 - In the admin panel you can toggle ldap, anonymous, permissions settings. As
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rhodecode/config/setup_rhodecode.py	Thu May 17 00:55:35 2012 +0200
@@ -0,0 +1,87 @@
+import os
+from paste.script.appinstall import AbstractInstallCommand
+from paste.script.command import BadCommand
+from paste.deploy import appconfig
+
+
+class SetupCommand(AbstractInstallCommand):
+
+    default_verbosity = 1
+    max_args = 1
+    min_args = 1
+    summary = "Setup an application, given a config file"
+    usage = "CONFIG_FILE"
+
+    description = """\
+    Note: this is an experimental command, and it will probably change
+    in several ways by the next release.
+
+    Setup an application according to its configuration file.  This is
+    the second part of a two-phase web application installation
+    process (the first phase is prepare-app).  The setup process may
+    consist of things like creating directories and setting up
+    databases.
+    """
+
+    parser = AbstractInstallCommand.standard_parser(
+        simulate=True, quiet=True, interactive=True)
+    parser.add_option('--user',
+                      action='store',
+                      dest='username',
+                      default=None,
+                      help='Admin Username')
+    parser.add_option('--email',
+                      action='store',
+                      dest='email',
+                      default=None,
+                      help='Admin Email')
+    parser.add_option('--password',
+                      action='store',
+                      dest='password',
+                      default=None,
+                      help='Admin password min 6 chars')
+    parser.add_option('--repos',
+                      action='store',
+                      dest='repos_location',
+                      default=None,
+                      help='Absolute path to repositories location')
+    parser.add_option('--name',
+                      action='store',
+                      dest='section_name',
+                      default=None,
+                      help='The name of the section to set up (default: app:main)')
+
+    def command(self):
+        config_spec = self.args[0]
+        section = self.options.section_name
+        if section is None:
+            if '#' in config_spec:
+                config_spec, section = config_spec.split('#', 1)
+            else:
+                section = 'main'
+        if not ':' in section:
+            plain_section = section
+            section = 'app:'+section
+        else:
+            plain_section = section.split(':', 1)[0]
+        if not config_spec.startswith('config:'):
+            config_spec = 'config:' + config_spec
+        if plain_section != 'main':
+            config_spec += '#' + plain_section
+        config_file = config_spec[len('config:'):].split('#', 1)[0]
+        config_file = os.path.join(os.getcwd(), config_file)
+        self.logging_file_config(config_file)
+        conf = appconfig(config_spec, relative_to=os.getcwd())
+        ep_name = conf.context.entry_point_name
+        ep_group = conf.context.protocol
+        dist = conf.context.distribution
+        if dist is None:
+            raise BadCommand(
+                "The section %r is not the application (probably a filter).  "
+                "You should add #section_name, where section_name is the "
+                "section that configures your application" % plain_section)
+        installer = self.get_installer(dist, ep_group, ep_name)
+        installer.setup_config(
+            self, config_file, section, self.sysconfig_install_vars(installer))
+        self.call_sysconfig_functions(
+            'post_setup_hook', installer, config_file)
--- a/rhodecode/lib/db_manage.py	Wed May 16 01:25:00 2012 +0200
+++ b/rhodecode/lib/db_manage.py	Thu May 17 00:55:35 2012 +0200
@@ -238,10 +238,15 @@
             self.sa.rollback()
             raise
 
-    def admin_prompt(self, second=False):
+    def admin_prompt(self, second=False, defaults={}):
         if not self.tests:
             import getpass
 
+            # defaults
+            username = defaults.get('username')
+            password = defaults.get('password')
+            email = defaults.get('email')
+
             def get_password():
                 password = getpass.getpass('Specify admin password '
                                            '(min 6 chars):')
@@ -255,17 +260,17 @@
                     return False
 
                 return password
-
-            username = raw_input('Specify admin username:')
-
-            password = get_password()
-            if not password:
-                #second try
+            if username is None:
+                username = raw_input('Specify admin username:')
+            if password is None:
                 password = get_password()
                 if not password:
-                    sys.exit()
-
-            email = raw_input('Specify admin email:')
+                    #second try
+                    password = get_password()
+                    if not password:
+                        sys.exit()
+            if email is None:
+                email = raw_input('Specify admin email:')
             self.create_user(username, password, email, True)
         else:
             log.info('creating admin and regular test users')
@@ -370,11 +375,14 @@
                 log.debug('missing default permission for group %s adding' % g)
                 ReposGroupModel()._create_default_perms(g)
 
-    def config_prompt(self, test_repo_path='', retries=3):
+    def config_prompt(self, test_repo_path='', retries=3, defaults={}):
+        _path = defaults.get('repos_location')
         if retries == 3:
             log.info('Setting up repositories config')
 
-        if not self.tests and not test_repo_path:
+        if _path is not None:
+            path = _path
+        elif not self.tests and not test_repo_path:
             path = raw_input(
                  'Enter a valid absolute path to store repositories. '
                  'All repositories in that path will be added automatically:'
--- a/rhodecode/lib/vcs/backends/git/changeset.py	Wed May 16 01:25:00 2012 +0200
+++ b/rhodecode/lib/vcs/backends/git/changeset.py	Thu May 17 00:55:35 2012 +0200
@@ -38,14 +38,11 @@
         self._tree_id = commit.tree
 
         try:
-            self.message = safe_unicode(commit.message[:-1])
-            # Always strip last eol
+            self.message = safe_unicode(commit.message)
         except UnicodeDecodeError:
-            self.message = commit.message[:-1].decode(commit.encoding
-                or 'utf-8')
+            self.message = commit.message.decode(commit.encoding or 'utf-8')
         #self.branch = None
         self.tags = []
-        #tree = self.repository.get_object(self._tree_id)
         self.nodes = {}
         self._paths = {}
 
--- a/rhodecode/tests/functional/test_files.py	Wed May 16 01:25:00 2012 +0200
+++ b/rhodecode/tests/functional/test_files.py	Thu May 17 00:55:35 2012 +0200
@@ -193,7 +193,7 @@
             short = '27cd5cce30c9%s' % arch_ext
             fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
             filename = '%s-%s' % (HG_REPO, short)
-            response = self.app.get(url(controller='files', 
+            response = self.app.get(url(controller='files',
                                         action='archivefile',
                                         repo_name=HG_REPO,
                                         fname=fname))
--- a/rhodecode/websetup.py	Wed May 16 01:25:00 2012 +0200
+++ b/rhodecode/websetup.py	Thu May 17 00:55:35 2012 +0200
@@ -40,9 +40,10 @@
                         tests=False)
     dbmanage.create_tables(override=True)
     dbmanage.set_db_version()
-    dbmanage.create_settings(dbmanage.config_prompt(None))
+    opts = dbmanage.config_prompt(None, defaults=command.options.__dict__)
+    dbmanage.create_settings(opts)
     dbmanage.create_default_user()
-    dbmanage.admin_prompt()
+    dbmanage.admin_prompt(defaults=command.options.__dict__)
     dbmanage.create_permissions()
     dbmanage.populate_default_permissions()
     Session.commit()
--- a/setup.py	Wed May 16 01:25:00 2012 +0200
+++ b/setup.py	Thu May 17 00:55:35 2012 +0200
@@ -94,6 +94,7 @@
     main = pylons.util:PylonsInstaller
 
     [paste.global_paster_command]
+    setup-rhodecode=rhodecode.config.setup_rhodecode:SetupCommand
     make-index=rhodecode.lib.indexers:MakeIndex
     make-rcext=rhodecode.config.rcextensions.make_rcextensions:MakeRcExt
     upgrade-db=rhodecode.lib.dbmigrate:UpgradeDb