Commits

Christophe Combelles  committed 1689fe1

Removed the instruction popup, and replace it with a page

  • Participants
  • Parent commits 7d0c99d

Comments (0)

Files changed (22)

File scripts/demo_CPS 3.5.sh

 exec zinstance/bin/runzope
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>To start using CPS, you must create a CPS site. Do the following:</p>
 <ol>
     <li>Click on <a href="manage_main">Zope Management Interface</a> and connect with the password you chose</li>

File scripts/demo_Drupal 6.sh

 exec /usr/sbin/mysqld --no-defaults --socket=./mysql/mysqld.sock --datadir=./mysql/ --log-error=./mysql/mysql-error.log --port=$((PORT+1000))
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>To finish the Drupal installation, do the following:</p>
 <ol>
     <li>Visit the <a href="install.php">install.php</a> page.</li>

File scripts/demo_Drupal 7.sh

 exec /usr/sbin/mysqld --no-defaults --socket=./mysql/mysqld.sock --datadir=./mysql/ --log-error=./mysql/mysql-error.log --port=$((PORT+1000))
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>To finish the Drupal installation, do the following:</p>
 <ol>
     <li>Visit the <a href="install.php">install.php</a> page.</li>

File scripts/demo_OpenERP 5.sh

 cat
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>To start using OpenERP, you must create a database. Do the following:</p>
 <ol>
     <li>Click on "Databases"</li>

File scripts/demo_OpenERP 6.0.sh

 cat
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>To start using OpenERP, you must create a database. Do the following:</p>
 <ol>
     <li>Click on "Databases"</li>

File scripts/demo_OpenERP 6.1.sh

 cat
 EOF
 
-# create a popup for installation instruction
-#cat > popup.html << EOF
-#<p>To start using OpenERP, you must create a database. Do the following:</p>
-#<ol>
-#    <li>Click on "Manage Databases"</li>
-#    <li>Click on "Create"</li>
-#    <li>Fill in the form:
-#        <ul>
-#            <li>Super admin password: <your admin password></li>
-#            <li>New database name: <your_database_name></li>
-#            <li>Load Demonstration data: check if you need demo data</li>
-#            <li>Default Language: choose your language</li>
-#            <li>Administrator password: <choose a password for the "admin" account></li>
-#            <li>Confirm password: <repeat the same password></li>
-#        </ul>
-#    <li>Click on OK, and wait a few seconds</li>
-#    <li>Start configuring your new database</li>
-#</ol>
-#EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
+<p>To start using OpenERP, you must create a database. Do the following:</p>
+<ol>
+    <li>Click on "Manage Databases"</li>
+    <li>Click on "Create"</li>
+    <li>Fill in the form:
+        <ul>
+            <li>Super admin password: <your admin password></li>
+            <li>New database name: <your_database_name></li>
+            <li>Load Demonstration data: check if you need demo data</li>
+            <li>Default Language: choose your language</li>
+            <li>Administrator password: <choose a password for the "admin" account></li>
+            <li>Confirm password: <repeat the same password></li>
+        </ul>
+    <li>Click on OK, and wait a few seconds</li>
+    <li>Start configuring your new database</li>
+</ol>
+EOF
 
 }
 

File scripts/demo_Plone 3.sh

 #
 #bin/instance run bin/initialize.py
 
-# create a popup for installation instruction
+# create a howto for installation instruction
 cd ..
-cat > popup.html << EOF
+cat > howto.html << EOF
 <p>To start using Plone 3, you must create a plone site. Do the following:</p>
 <ol>
     <li>Click on <a href="manage_main">Zope Management Interface</a> and connect with the password you chose</li>

File scripts/demo_Prestahop.sh

 #!/bin/bash
 # PARAMS: name, version=1.4.8.2
+set -x
 
 export db_host=127.0.0.1
 export db_port=$((PORT+1000))
 wget $url -O  prestashop.zip
 unzip prestashop.zip
 
-# change install form to have default config for db
-sed -i "s/localhost/$db_host:$db_port/" prestashop/install/index.php
-sed -i "s/root/$db_user/" prestashop/install/index.php
-sed -i "s/type=\"password\" id=\"dbPassword\"\/>/type=\"password\" id=\"dbPassword\" value=\"$db_pass\"\/>/" prestashop/install/index.php
+if [ "$version" ">" "1.5.0.0" ]; then 
+    sed -i "s/database_server = 'localhost'/database_server = '$db_host:$db_port'/" prestashop/install/controllers/http/database.php
+    sed -i "s/database_login = 'root'/database_login = '$db_user'/" prestashop/install/controllers/http/database.php
+    sed -i "s/database_password = ''/database_password = '$db_pass'/" prestashop/install/controllers/http/database.php
+else
+    # change install form to have default config for db
+    sed -i "s/localhost/$db_host:$db_port/" prestashop/install/index.php
+    sed -i "s/root/$db_user/" prestashop/install/index.php
+    sed -i "s/type=\"password\" id=\"dbPassword\"\/>/type=\"password\" id=\"dbPassword\" value=\"$db_pass\"\/>/" prestashop/install/index.php
+fi
 
 # create the Apache config
 cat > apache2.conf << EOF
 exec /usr/sbin/mysqld --no-defaults --socket=./mysql/mysqld.sock --datadir=./mysql/ --log-error=./mysql/mysql-error.log --port=$db_port
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>When you have finished the Prestashop installation wizard, do the following:</p>
 <ol>
-  <li>First <a href="/showroom_manage/postinstall?app=$name">click here</a>to delete the install folder and rename /admin to /myadmin</li>
+  <li>First <a href="/showroom_manage/postinstall?app=$name">click here</a> to delete the install folder and rename /admin to /myadmin</li>
   <li>Then you can go to your Prestashop <a href="/myadmin">Admin panel</a></li>
 </ol>
 EOF
 
 function reconfigure_clone {
 # $1 is the old name, $2 is the old port
-sed -i "s/app=$1/app=$name/" popup.html
+sed -i "s/app=$1/app=$name/" howto.html
 sed -i "s/\/$1\//\/$name\//" apache2.conf
 sed -i "s/$2/$PORT/" apache2.conf
-sed -i "s/$(($2 + 1000))/$db_port/" prestashop/install/index.php
+if [ "$version" ">" "1.5.0.0" ]; then 
+    sed -i "s/$(($2 + 1000))/$db_port/" prestashop/install/controllers/http/database.php
+else
+    sed -i "s/$(($2 + 1000))/$db_port/" prestashop/install/index.php
+fi
 sed -i "s/$(($2 + 1000))/$db_port/" start.sh
 }
 

File scripts/demo_SugarCRM.sh

 
 # create a startup script
 cat > start.sh << EOF
-DIR=`pwd`
-exec /usr/sbin/mysqld --no-defaults --socket=$DIR/mysql/mysqld.sock --datadir=$DIR/mysql/ --log-error=$DIR/mysql/mysql-error.log --port=$db_port
+exec /usr/sbin/mysqld --no-defaults --socket=./mysql/mysqld.sock --datadir=./mysql/ --log-error=./mysql/mysql-error.log --port=$db_port
 EOF
 }
 

File scripts/demo_karl.sh

 exec bin/paster serve etc/karl.ini
 EOF
 
-# create a popup for installation instruction
-cat > popup.html << EOF
+# create a howto for installation instruction
+cat > howto.html << EOF
 <p>The initial user account is<br/>
 user : admin<br/>
 pass : admin</p>
       [console_scripts]
       signup_setup = pyramid_signup.scripts.populate:main
       [paste.app_factory]
-      pyramid = showroom.run:showroom
+      admin = showroom.run:showroom
       [paste.filter_factory]
       proxy = showroom.proxy:make_filter
       """

File showroom/configure.zcml

          view_attr="destroy"
          view_permission="edit"
   />
-
   <route name="json_installed_demos"
          path="/json_installed_demos"
          view=".views.json_installed_demos"
          renderer="json"
          view_permission="edit"
   />
-
   <route name="app_scripts"
          path="/script"
          view=".views.DemoController"
          view_attr="app_script"
          view_permission="edit"
   />
-
   <route name="postinstall"
          path="/postinstall"
          view=".views.DemoController"
          view_attr="postinstall"
          view_permission="edit"
   />
-
+  <route name="howto"
+         path="/howto"
+         view=".views.DemoController"
+         view_attr="howto"
+         view_permission="view"
+  />
   <static
      name="static"
      path="templates/static"

File showroom/models.py

 from pyramid.security import Allow, Authenticated, ALL_PERMISSIONS
+import utils
+from urlparse import urlsplit, urlunsplit
 
 class RootFactory(object):
     """ root object factory for the whole app
     """
     def __init__(self, request):
         self.request = request
+        current_host = urlsplit(request.host_url)
+        admin_url = urlunsplit((current_host.scheme,
+                                utils.ADMIN_HOST, '/', '', ''))
+        self.request['admin_url'] = admin_url
         self.is_root = True
 
     @property

File showroom/proxy.py

 # -*- coding: utf-8 -*-
-from os.path import join, dirname, abspath
 from webob import Request, Response
 from webob.exc import HTTPFound
 from wsgiproxy.exactproxy import proxy_exact_request
 #logging.basicConfig(level=logging.DEBUG)
 LOG = logging.getLogger(__name__)
 
-CSS = '''
-<link href="/showroom_static/jquery/css/showroom/jquery-ui-1.8.16.custom.css" type="text/css" rel="stylesheet" />
-<link href="/showroom_static/popup.css" type="text/css" rel="stylesheet" />
-'''
-
-JS = '''
-<script type="text/javascript" src="/showroom_static/jquery/js/jquery-1.6.2.min.js"></script>
-<script type="text/javascript" src="/showroom_static/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
-<script type="text/javascript">
-    $.noConflict();
-    jQuery(document).ready(function($) {
-        $("#showroompopup").dialog({width: "40%%", title: 'Installation instructions'}).parents(".ui-dialog:eq(0)").wrap('<div id="showroomscope"></div>');
-        $('#showroompopup_hide form input').click(
-            function() {
-                $.get(window.location.protocol + '//' + window.location.host + '/?showroompopup_hide');
-                $("#showroompopup").parent().hide();
-            }
-        );
-    })
-</script>
-'''
 
 class Proxy(object):
     """ wsgi middleware that acts as a proxy, or redirects to the admin
         request.path_info = path_info
         request.environ['SERVER_NAME'] = 'localhost'
         request.environ['SERVER_PORT'] = demo.port
-        # disable compression to be able to insert the js popup
-        request.environ['HTTP_ACCEPT_ENCODING'] = ''
         response = request.get_response(proxy_exact_request)
 
-        # disable the popup if asked
-        if 'showroompopup_hide' in environ['QUERY_STRING']:
-            demo.disable_popup()
-
-        # inject the information popup
-        content = demo.popup
-        if content is not None and demo.is_popup_displayed:
-            popup = open(join(abspath(dirname(__file__)),
-                              'templates', 'popup.html')).read() % content
-
-            if 'html' in (response.content_type or ''):
-                if '</body>' in response.body and '<head>' in response.body:
-                    response.body = response.body.replace('</head>', CSS + JS + '</head>')
-                    response.body = response.body.replace('</body>', popup + '</body>')
-                else:
-                    response.body = CSS + JS + response.body + popup
-
         return response(environ, start_response)
 
 

File showroom/templates/demo.pt

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:tal="http://xml.zope.org/namespaces/tal"
+      xmlns:metal="http://xml.zope.org/namespaces/metal"
+      metal:use-macro="master.macros['master']">
+<head>
+  <title>Showroom</title>
+</head>
+
+<body>
+
+<!-- header -->
+<div id="header">
+
+  <!-- user -->
+  <div metal:fill-slot="header" id="user_ID">
+      <a href='/profile/${logged_in.pk}'>${logged_in.first_name} ${logged_in.last_name} (${logged_in.username})</a>
+      - 
+      <a href='${request.application_url}/logout'>Log out</a>
+  </div>
+</div>
+
+<div id="content" metal:fill-slot="content">
+
+  <h2>Demo of ${demo.type} ${demo.version} (${demo.name})</h2>
+
+TODO button start/stop/destroy
+
+  <h2>Instructions</h2>
+  <div style="margin-bottom: 2em" tal:content="structure howto">
+    howto
+  </div>
+
+</div>
+
+</body>
+</html>

File showroom/templates/demos.pt

       </td>
       <td class="demo_title">
         <a tal:attributes="href python: proxied_url(demo, request)"
-           tal:content="python: demo.get('name')">
+           tal:content="python: demo.get('name')"
+           target="_new">
             app name
         </a>
       </td>
             (direct link)
         </a>
       </td>
+      <td class="demo_instructions">
+        <a tal:attributes="href python: proxied_url(demo, request) + 'showroom_manage/howto?name=' + demo.get('name')">
+            (instructions)
+        </a>
+      </td>
       <td class="demo_button">
         <a href="#" class="start"
            tal:condition="python: demo['status'] in ('STOPPED', 'FATAL')"

File showroom/templates/master.pt

   <div id="header">
     <!-- logo -->
     <div id="logo">
-        <a href="${request.application_url}">
+        <a href="${request['admin_url']}">
             <img src="${request.application_url}/static/images/logo.png" alt="logo" />
         </a>
     </div>

File showroom/templates/popup.html

-<div id="showroompopup" style="display: none">
-  <div id="showroomlogo">
-      <img src="/showroom_static/images/logo.png" border="0" />
-  </div>
-  <div style="margin-bottom: 2em">
-    %s
-  </div>
-<div id="showroompopup_hide"><form method="POST" action=""><input type="checkbox" name="showroompopup_hide"/>Hide this popup<input type="hidden" name="toto" value="titi"/></form></div>
-</div>

File showroom/templates/static/default.css

     border: solid 1px #555;
 }
 
+td.demo_instructions {
+    font-size: 100%;
+    padding: 0em 1em;
+    vertical-align: middle;
+    text-shadow: 0 1px 0 #CCC;
+}
 td.demo_title {
     font-size: 120%;
     padding: 0em 1em;

File showroom/templates/static/popup.css

-/* Add css missing from jquery ui */
-#showroompopup a:link {
-background-color: transparent;
-}
-
-/* additional style for the popup contents */
-#showroomscope > div {
--moz-box-shadow: 5px 7px 7px 0px #737373;
--webkit-box-shadow: 5px 7px 7px 0px #737373;
-}
-#showroomscope .ui-dialog-titlebar {
-line-height: 0.5em;
-}
-#showroomscope {
-font-size: 8pt;
-line-height: 1.5em;
-}
-#showroompopup img {
-float: none;
-margin-bottom: 0.5em;
-}
-#showroomscope a {
-color: blue;
-}
-#showroomscope a:hover {
-color: red;
-}
-#showroomscope a:visited, #showroomscope a {
-text-decoration: underline;
-}
-
-#showroompopup_hide {
-position: absolute;
-bottom: 0.5em;
-right: 0.5em;
-}
-

File showroom/utils.py

         self.apache_config_dir = join(PATHS['var'], 'apache2', 'demos')
         self.apache_config_link = join(self.apache_config_dir,
                                        user + '.' + name + '.conf')
-        self.popup = None
-        self.popup_file = join(self.path, 'popup.html')
-        if self.has_popup:
-            with open(self.popup_file) as p:
-                self.popup = p.read()
+
+        self.howto_file = join(self.path, 'howto.html')
         # read the demo config
         self.democonf = SafeConfigParser()
         self.democonf_path = join(self.path, 'demo.conf')
             self.port = ''
         # get the real name of the demo
         self.name = self.democonf.get('params', 'name')
+        if self.democonf.has_option('params', 'type'):
+            self.type = self.democonf.get('params', 'type')
+        else:
+            self.type = 'Unknown'
+        if self.democonf.has_option('params', 'version'):
+            self.version = self.democonf.get('params', 'version')
+        else:
+            self.version = ''
 
         # init the supervisor
         self.supervisor = SuperVisor(self.user)
     has_startup_script = property(lambda self: os.path.exists(self.start_script))
     has_apache_link = property(lambda self: os.path.exists(self.apache_config_link))
     has_apache_conf = property(lambda self: os.path.exists(self.apache_config_file))
-    has_popup = property(lambda self: os.path.exists(self.popup_file))
-
-    @property
-    def is_popup_displayed(self):
-        """tells if the popup should be displayed
-        """
-        try:
-            return self.democonf.getboolean('params', 'displaypopup')
-        except Exception:
-            return True
-
-    def disable_popup(self):
-        """disable the popup
-        """
-        self.democonf.set('params', 'displaypopup', '0')
-        with open(self.democonf_path, 'w') as democonf_file:
-            self.democonf.write(democonf_file)
+    has_howto = property(lambda self: os.path.exists(self.howto_file))
 
     def get_status(self):
         """return the status of the demo
         else:
             return 'FATAL'
 
+    def howto(self):
+        """retrieve the howto
+        """
+        if self.has_howto:
+            with open(join(self.path, 'howto.html')) as howto_file:
+                return howto_file.read()
+        else:
+            return 'No specific instructions'
+
     def start(self):
         """start the demo
         """
     app_conf.add_section('params')
     app_conf.set('params', 'port', str(port))
     app_conf.set('params', 'name', app_name.encode('utf-8'))
+    app_conf.set('params', 'type', app_type.encode('utf-8'))
     app_conf.set('params', 'status', 'DEPLOYING')
     for param_name, param_value in params.items():
         assert(param_name not in ('port', 'status'))

File showroom/views.py

 # coding: utf-8
 from os.path import join, abspath, dirname
-from pyramid.chameleon_zpt import get_template
-from pyramid.chameleon_zpt import render_template_to_response
+from pyramid.chameleon_zpt import get_template, render_template_to_response
 from pyramid.exceptions import NotFound
 from pyramid.i18n import TranslationStringFactory
 from pyramid.request import Response
 from pyramid.security import authenticated_userid
 from pyramid_signup.managers import UserManager
 from urlparse import urlsplit, urlunsplit
-from utils import ADMIN_HOST
-from utils import keep_working_dir
 from webob.exc import HTTPFound
-import deform
-import logging
-import os
+import os, deform, logging, subprocess
 import pyramid_signup.views
-import subprocess
 import utils
 
 LOG = logging.getLogger(__name__)
     current_host = urlsplit(request.host_url)
     port = current_host.port
     if port is None:
-        host = ADMIN_HOST
+        host = utils.ADMIN_HOST
     else:
-        host = ADMIN_HOST + ':' + str(current_host.port)
+        host = utils.ADMIN_HOST + ':' + str(current_host.port)
     return urlunsplit(
         (current_host.scheme, demo['name'] + '.' + user.username + '.' + host, '/', '', ''))
 
         return "#"
     current_host = urlsplit(request.host_url)
     return urlunsplit(
-        (current_host.scheme, ADMIN_HOST + ':' + demo['port'], '/', '', ''))
+        (current_host.scheme, utils.ADMIN_HOST + ':' + demo['port'], '/', '', ''))
 
 def installed_demos(request):
     """ return the main page, with applications list, and actions.
     def __init__(self, request):
         self.request = request
         self.user = authenticated_userid(self.request)
+        self.name = self.request.params.get('name', '').replace(' ', '_').lower() # FIXME?
         if self.user is not None:
             self.user = UserManager(request).get_by_pk(self.user)
 
         params = dict(self.request.params.copy())
         if 'app' not in params or 'name' not in params:
             raise NotFound
-        name = params['name'] = params['name'].replace(' ', '_').lower() # FIXME
+        name = params['name'] = self.name
         if 'plugins' in params:
             params['plugins'] = ' '.join(params['plugins'].split())
         try:
     def start(self):
         """ view that starts the demo
         """
-        name = self.request.params.get('name', '_')
-        demo = utils.InstalledDemo(self.user.username, name)
+        demo = utils.InstalledDemo(self.user.username, self.name)
     
         old_status = demo.get_status()
         message = u'Nothing changed'
     def stop(self):
         """ view that stops a demo
         """
-        name = self.request.params.get('name', '_')
-        demo = utils.InstalledDemo(self.user.username, name)
+        demo = utils.InstalledDemo(self.user.username, self.name)
     
         old_status = demo.get_status()
         message = u'Nothing changed'
     def destroy(self):
         """ Destroy a demo
         """
-        name = self.request.params['name']
         try:
-            utils.InstalledDemo(self.user.username, name).destroy()
+            utils.InstalledDemo(self.user.username, self.name).destroy()
         except Exception, e:
             message = 'Error: %s' % e.message
             self.request.session.flash(message, 'error')
             return HTTPFound(location='/')
     
-        self.request.session.flash('%s demo successfully deleted!' % name, 'success')
+        self.request.session.flash('%s demo successfully deleted!' % self.name, 'success')
         return HTTPFound(location='/')
 
 
                     start = '#!/bin/bash\n'
                 content = start + content
                 s.seek(0); s.truncate(); s.write(content)
-            with keep_working_dir:
+            with utils.keep_working_dir:
                 os.chdir(demo.path)
                 subprocess.call(['chmod', '+x', script])
                 subprocess.call([script])
             os.rename(script, script + '.executed')
         return HTTPFound(location=getattr(self.request, 'referrer', False) or '/')
 
+    def howto(self):
+        """Display the howto for the demo
+        """
+        demo = utils.InstalledDemo(self.user.username, self.name)
+        return render_template_to_response(
+            join(abspath(dirname(__file__)), 'templates', 'demo.pt'),
+            master=get_template(join('templates', 'master.pt')),
+            request=self.request,
+            proxied_url=proxied_url,
+            howto=demo.howto(),
+            demo=demo,
+            supervisor=utils.SuperVisor(self.user).is_running,
+            logged_in=self.user,
+            )
+
 
 class MainController(object):
     def __init__(self, request):