apps.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 usage: %(progname)s [args]
5 """
6 
7 import os, sys, string, time, getopt, re
8 
9 import neo_cgi, neo_util, neo_cs
10 
11 from pyclearsilver import CSPage
12 from pyclearsilver import odb
13 from pyclearsilver.log import *
14 
15 import MBPage
16 import db_webui
17 import webutil
18 import config
19 
20 import launchman.app
21 
22 
24  def setup(self, hdf):
25  self.db = db_webui.initSchema()
26 
27  def display(self, hdf):
28  webutil.grabTopics(hdf, [])
29 
30  hdf.setValue("CGI.now", str(time.time()))
31  webutil.set_tabs(hdf, ["apps"])
32 
33  apps = self.db.apps.fetchAllRows()
34  prefix = "CGI.cur.apps"
35  i = 0
36  for app in apps:
37  i = i + 1
38  aprefix = prefix + ".%d" % i
39  app.hdfExport(aprefix, hdf)
40  app.fetchApp(aprefix, hdf)
41 
42  # experimental new stuff
43  apps = webutil.list_apps()
44  categories = {}
45  user_record = self.authdb.users.lookup(self.username)
46  user_apps = user_record.favorite_apps_list()
47 
48  taskids = [db_webui.path2taskid(app) for app in apps]
49  actual_apps = []
50 
51  for user_app in user_apps:
52  if user_app in taskids:
53  actual_apps.append(user_app)
54  categories["Favorites"] = actual_apps
55 
56  n = 0
57  for appfn in apps:
58  taskid = db_webui.path2taskid(appfn)
59  n = n + 1
60  prefix = "CGI.cur.available_apps.%s" % taskid
61  _app = launchman.app.App(taskid)
62  doc = _app.load_yaml()
63 
64  iapp = self.db.apps.lookup(taskid=taskid)
65  if iapp:
66  pass
67 
68  # only show apps relevant to this type of robot
69  robot_type = config.get_robot_type()
70  if "robot" in doc and robot_type != doc["robot"]:
71  continue
72 
73  try:
74  category_apps = categories[doc.get("category", "Other")]
75  except KeyError:
76  category_apps = []
77  categories[doc.get("category", "Other")] = category_apps
78  category_apps.append(taskid)
79 
80  hdf.setValue(prefix + ".taskid", taskid)
81  for key, val in doc.items():
82  if type(val) is list:
83  for i in range(0,len(val)):
84  hdf.setValue(prefix + "." + key + "." + str(i), val[i])
85  elif val is not None:
86  hdf.setValue(prefix + "." + key, val)
87  else:
88  hdf.setValue(prefix + "." + key, '')
89 
90  if user_record.is_favorite_app(taskid):
91  hdf.setValue(prefix + ".favorite", "1")
92 
93  def compare_categories(a, b):
94  if a[0] == "Favorites":
95  return -1
96  if b[0] == "Favorites":
97  return 1
98  else:
99  return cmp(a, b)
100 
101  prefix = "CGI.cur.categories"
102  i = 0
103  for category, apps in sorted(categories.items(), compare_categories):
104  hdf.setValue(prefix + ".%d" % i, category)
105  j = 0
106  for app in apps:
107  hdf.setValue(prefix + ".%d.apps.%d" % (i, j), app)
108  j = j + 1
109  i = i + 1
110 
111 def run(context):
112  return MyPage(context, pagename="apps", nologin=False)
113 
114 def main():
115  context = CSPage.Context()
116  run(context).start()
117 
118 if __name__ == "__main__":
119  main()
def run(context)
Definition: apps.py:111


webui
Author(s): Scott Hassan
autogenerated on Mon Jun 10 2019 15:51:24