Go to the documentation of this file.00001
00002
00003 """
00004 usage: %(progname)s [args]
00005 """
00006
00007 import os, sys, string, time, getopt, re
00008
00009 import neo_cgi, neo_util, neo_cs
00010
00011 from pyclearsilver import CSPage
00012 from pyclearsilver import odb
00013 from pyclearsilver.log import *
00014
00015 import MBPage
00016 import db_webui
00017 import webutil
00018 import config
00019
00020 import launchman.app
00021
00022
00023 class MyPage(MBPage.MBPage):
00024 def setup(self, hdf):
00025 self.db = db_webui.initSchema()
00026
00027 def display(self, hdf):
00028 webutil.grabTopics(hdf, [])
00029
00030 hdf.setValue("CGI.now", str(time.time()))
00031 webutil.set_tabs(hdf, ["apps"])
00032
00033 apps = self.db.apps.fetchAllRows()
00034 prefix = "CGI.cur.apps"
00035 i = 0
00036 for app in apps:
00037 i = i + 1
00038 aprefix = prefix + ".%d" % i
00039 app.hdfExport(aprefix, hdf)
00040 app.fetchApp(aprefix, hdf)
00041
00042
00043 apps = webutil.list_apps()
00044 categories = {}
00045 user_record = self.authdb.users.lookup(self.username)
00046 user_apps = user_record.favorite_apps_list()
00047
00048 taskids = [db_webui.path2taskid(app) for app in apps]
00049 actual_apps = []
00050
00051 for user_app in user_apps:
00052 if user_app in taskids:
00053 actual_apps.append(user_app)
00054 categories["Favorites"] = actual_apps
00055
00056 n = 0
00057 for appfn in apps:
00058 taskid = db_webui.path2taskid(appfn)
00059 n = n + 1
00060 prefix = "CGI.cur.available_apps.%s" % taskid
00061 _app = launchman.app.App(taskid)
00062 doc = _app.load_yaml()
00063
00064 iapp = self.db.apps.lookup(taskid=taskid)
00065 if iapp:
00066 pass
00067
00068
00069 robot_type = config.get_robot_type()
00070 if "robot" in doc and robot_type != doc["robot"]:
00071 continue
00072
00073 try:
00074 category_apps = categories[doc.get("category", "Other")]
00075 except KeyError:
00076 category_apps = []
00077 categories[doc.get("category", "Other")] = category_apps
00078 category_apps.append(taskid)
00079
00080 hdf.setValue(prefix + ".taskid", taskid)
00081 for key, val in doc.items():
00082 if type(val) is list:
00083 for i in range(0,len(val)):
00084 hdf.setValue(prefix + "." + key + "." + str(i), val[i])
00085 elif val is not None:
00086 hdf.setValue(prefix + "." + key, val)
00087 else:
00088 hdf.setValue(prefix + "." + key, '')
00089
00090 if user_record.is_favorite_app(taskid):
00091 hdf.setValue(prefix + ".favorite", "1")
00092
00093 def compare_categories(a, b):
00094 if a[0] == "Favorites":
00095 return -1
00096 if b[0] == "Favorites":
00097 return 1
00098 else:
00099 return cmp(a, b)
00100
00101 prefix = "CGI.cur.categories"
00102 i = 0
00103 for category, apps in sorted(categories.items(), compare_categories):
00104 hdf.setValue(prefix + ".%d" % i, category)
00105 j = 0
00106 for app in apps:
00107 hdf.setValue(prefix + ".%d.apps.%d" % (i, j), app)
00108 j = j + 1
00109 i = i + 1
00110
00111 def run(context):
00112 return MyPage(context, pagename="apps", nologin=False)
00113
00114 def main():
00115 context = CSPage.Context()
00116 run(context).start()
00117
00118 if __name__ == "__main__":
00119 main()