Permalink
Browse files

Wizards are introspected now. The old system based on directories is

gone for good.

git-svn-id: svn://cherokee-project.com/wizards2@6808 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent fa3a0dc commit 7e7908d8e1e4e0f8650e605f3d07a6ec811639bc @alobbs alobbs committed Aug 15, 2011
View
@@ -66,64 +66,98 @@
return false;
"""
-class CategoryList_Widget (CTK.Box):
- def __init__ (self, category, wizards_type):
- CTK.Box.__init__ (self)
- self.category = category
+_wizards_objs = []
+def load_wizards():
+ # Cache Miss
+ global _wizards_objs
+ if not _wizards_objs:
# Locate the directory
wizards_path = os.path.realpath (__file__ + "/../wizards")
- wlist = CTK.List({'class': 'wizard-list'})
- entries = os.listdir (wizards_path)
-
- for entry in entries:
- if not entry.startswith("%s-"%(category)):
+ wizards = os.listdir (wizards_path)
+ for wizard in wizards:
+ # Skip back-ups
+ if (wizard.startswith ('.')) or ('#' in wizard) or (not wizard.endswith('.py')):
continue
- # Wizards of the category
- wizards = os.listdir (os.path.join (wizards_path, entry))
+ # Load the wizard
+ wizard_name = wizard.replace('.py', '')
+ wizard_fp = os.path.join (wizards_path, wizard_name)
+ mod = CTK.load_module (wizard_fp, wizard.replace('.py', ''))
+
+ # Update Cache
+ _wizards_objs.append (mod)
+
+ return _wizards_objs
+
+class Icon (CTK.Image):
+ def __init__ (self, wizard_mod, _props={}):
+ icon = wizard_mod.software['icon_small']
+ name = wizard_mod.software['name']
- for wizard in wizards:
- if not wizard.endswith ('.py') or \
- wizard.startswith ('.') or \
- '#' in wizard:
- continue
+ props = _props.copy()
+ props['src'] = '/static/images/wizards2/%s'%(icon)
+ props['alt'] = "%s logo" %(name)
- wizard_name = wizard.replace('.py', '')
- wizard_fp = os.path.join (wizards_path, entry, wizard_name)
+ if 'class' in props:
+ props['class'] += ' wizard-icon'
+ else:
+ props['class'] = 'wizard-icon'
- mod = CTK.load_module (wizard_fp, wizard.replace('.py', ''))
- wlist.Add ([CTK.RawHTML ("<h1>%s</h1>" %(wizard_fp))],
- {'wizard': wizard.replace('.py','')})
+ CTK.Image.__init__ (self, props)
- # Category found: done
- break
- # Assembling
+class CategoryList_Widget (CTK.Box):
+ def __init__ (self, category_num, wizards_type):
+ CTK.Box.__init__ (self)
+
+ self.category_num = int(category_num)
+ self.category_name = get()[self.category_num]
+
+ # GUI
+ wlist = CTK.List({'class': 'wizard-list'})
hidden = CTK.Hidden ('wizard')
+
submit = CTK.Submitter (URL_CAT_APPLY)
submit += wlist
submit += hidden
submit += CTK.RawHTML (js = JS_WIZARD_LIST %({'list_id': self.id}))
submit.bind ('submit_success', JS_WIZARD_LIST_SUBMIT %({'hidden': hidden.id}))
+
self += submit
+ # Fill the list
+ for wizard_mod in load_wizards():
+ if not 'software' in wizard_mod.__dict__:
+ continue
+
+ if wizard_mod.software['category'] != self.category_name:
+ continue
+
+ w_name = wizard_mod.software['name']
+ w_id = wizard_mod.software['id']
+ w_desc = wizard_mod.software['desc_short']
+
+ wlist.Add ([CTK.Box({'class': 'logo'}, Icon(wizard_mod)),
+ CTK.Box({'class': 'title'}, CTK.RawHTML(_(w_name))),
+ CTK.Box({'class': 'descr'}, CTK.RawHTML(_(w_desc)))],
+ {'wizard': w_id})
+ return
+
def CategoryList_Vsrv():
# Figure the category
- category = re.findall (URL_CAT_LIST_VSRV_R, CTK.request.url)[0]
+ category_num = re.findall (URL_CAT_LIST_VSRV_R, CTK.request.url)[0]
- # Instance and Render
- content = CategoryList_Widget (category, TYPE_VSERVER)
+ content = CategoryList_Widget (category_num, TYPE_VSERVER)
return content.Render().toJSON()
def CategoryList_Rule():
# Figure the category
- category = re.findall (URL_CAT_LIST_RULE_R, CTK.request.url)[0]
+ category_num = re.findall (URL_CAT_LIST_RULE_R, CTK.request.url)[0]
- # Instance and Render
- content = CategoryList_Widget (category, TYPE_RULE)
+ content = CategoryList_Widget (category_num, TYPE_RULE)
return content.Render().toJSON()
def CategoryList_Apply():
@@ -139,17 +173,15 @@ def CategoryList_Apply():
# Utilities
#
+_wizard_categories = []
def get():
- wizards_path = os.path.realpath (__file__ + "/../wizards")
-
- categories = {}
- entries = os.listdir (wizards_path)
-
- for entry in entries:
- tmp = re.findall (r'^(\d\d)-(.+)$', entry)
- if not tmp:
- continue
-
- categories[tmp[0][1]] = tmp[0][0]
+ global _wizard_categories
+ if not _wizard_categories:
+ categories = []
+ for wizard_mod in load_wizards():
+ if not 'software' in wizard_mod.__dict__:
+ continue
+ categories.append (wizard_mod.software['category'])
+ _wizard_categories = list(set(categories))
- return categories
+ return _wizard_categories
File renamed without changes.
@@ -31,6 +31,10 @@
php_tpl = Wizard2.Load_Template ('PHP.py')
+#
+# Configuration
+#
+
CONFIG_VSERVER = """
vserver!%(vserver_num)s!nick = %(vserver_nick)s
vserver!%(vserver_num)s!document_root = %(app_dir)s
@@ -96,10 +100,29 @@
"""
#
-# Installer
+# Public info
#
TARBALL = "http://wordpress.org/latest.tar.gz"
+DESC_SHORT = """WordPress is a state-of-the-art, semantic, personal
+publishing platform with a focus on aesthetics, Web standards, and
+usability. It was born out of a desire for an elegant,
+well-architected personal publishing system.
+"""
+
+software = {
+ 'id': 'wordpress',
+ 'name': 'WordPress',
+ 'author': 'Wordpress Community',
+ 'URL': 'http://wordpress.org/',
+ 'icon_small': 'wordpress_x96.png',
+ 'desc_short': DESC_SHORT,
+ 'category': 'Content Management',
+}
+
+#
+# Installer
+#
class Install (php_tpl.Install):
def __init__ (self, params):
php_tpl.Install.__init__ (self,
@@ -111,8 +134,9 @@ def __init__ (self, params):
def Check_Prerequisites (self):
errors = php_tpl.Install.Check_Prerequisites (self)
- errors += self._Prerequisite__MySQL()
- return errors
+ if errors: return errors
+
+ return self._Prerequisite__MySQL()
def _Handle_Unpacking (self):
errors = php_tpl.Install._Handle_Unpacking (self)
@@ -128,9 +152,7 @@ def Configure_Cherokee_PostApply (self):
if self.type == 'vserver':
vserver.Add_Usual_Static_Files (self.cfg_replacements['pre_rule_plus1'])
-
#
# GUI
#
-
GUI.Register_Standard_GUI ('Wordpress', Install, TARBALL)

0 comments on commit 7e7908d

Please sign in to comment.