def filter_xml(my, xml): dirname = os.path.dirname(my.rel_path) # filter images img_nodes = xml.get_nodes("//img") install_dir = Environment.get_install_dir() for node in img_nodes: src = xml.get_attribute(node, "src") if src.startswith("/tactic/plugins/"): plugin_dir = Environment.get_plugin_dir() path = "%s/%s" % (plugin_dir, src.replace("/tactic/plugins/", "")) elif src.startswith("/tactic/builtin_plugins/"): plugin_dir = Environment.get_builtin_plugin_dir() path = "%s/%s" % (plugin_dir, src.replace("/tactic/builtin_plugins/", "")) elif src.startswith("/"): path = "%s/src%s" % (install_dir, src) else: path = "%s/doc/%s/%s" % (install_dir, dirname, src) size = (0, 0) try: from PIL import Image im = Image.open(path) size = im.size except IOError, e: print "Error importing Image: ", e except:
def _get_template_config(self): base_dir = Environment.get_install_dir() file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view='template') return widget_config
def init(my): my.search_type = my.kwargs.get('search_type') my.page_title = my.kwargs.get('page_title') my.use_short_search_type_label = (my.kwargs.get('use_short_search_type_label') in ['true','True','TRUE',True]) my.html_template_dir = "%s/src/context/html_templates" % Environment.get_install_dir()
def generate(my, texts, font_sizes=15): if isinstance(texts, basestring): texts = [texts] if type(font_sizes) == types.IntType: font_sizes = [font_sizes] font_size = font_sizes[0] length = len(texts[0]) width = int(font_size * 0.6 * length + 50) im = Image.new("RGBA", (width, 100)) draw = ImageDraw.Draw(im) install_dir = Environment.get_install_dir() #/home/apache/tactic/src/pyasm/security/arial.ttf font_path = "%s/src/pyasm/security/arial.ttf" % install_dir for i, text in enumerate(texts): font = ImageFont.truetype(font_path, font_sizes[i]) interval = int(font_size) offset = int(font_size / 2) draw.text((20, i * interval), text, font=font, fill='#000') draw.text((20 + offset, i * interval + offset), text, font=font, fill='#FFF') return im
def init(self): self.search_type = self.kwargs.get('search_type') self.page_title = self.kwargs.get('page_title') self.use_short_search_type_label = (self.kwargs.get('use_short_search_type_label') in ['true','True','TRUE',True]) self.html_template_dir = "%s/src/context/html_templates" % Environment.get_install_dir()
def filter_xml(my, xml): dirname = os.path.dirname(my.rel_path) # filter images img_nodes = xml.get_nodes("//img") install_dir = Environment.get_install_dir() for node in img_nodes: src = xml.get_attribute(node, "src") if src.startswith("/tactic/plugins/"): plugin_dir = Environment.get_plugin_dir() path = "%s/%s" % (plugin_dir, src.replace("/tactic/plugins/", "") ) elif src.startswith("/tactic/builtin_plugins/"): plugin_dir = Environment.get_builtin_plugin_dir() path = "%s/%s" % (plugin_dir, src.replace("/tactic/builtin_plugins/", "") ) elif src.startswith("/"): path = "%s/src%s" % (install_dir, src) else: path = "%s/doc/%s/%s" % (install_dir, dirname, src) size = (0,0) try: from PIL import Image im = Image.open(path) size = im.size except IOError, e: print "Error importing Image: ", e except:
def generate(my, texts, font_sizes=15): if isinstance(texts, basestring): texts = [texts] if type(font_sizes) == types.IntType: font_sizes = [font_sizes] font_size = font_sizes[0] length = len(texts[0]) width = int(font_size * 0.6 * length + 50) im = Image.new("RGBA", (width, 100)) draw = ImageDraw.Draw(im) install_dir = Environment.get_install_dir() #/home/apache/tactic/src/pyasm/security/arial.ttf font_path = "%s/src/pyasm/security/arial.ttf" % install_dir for i, text in enumerate(texts): font = ImageFont.truetype(font_path, font_sizes[i]) interval = int(font_size) offset = int(font_size/2) draw.text((20, i*interval), text, font=font, fill='#000') draw.text((20+offset, i*interval+offset), text, font=font, fill='#FFF') return im
def _get_template_config(my): base_dir = Environment.get_install_dir() file_path = "%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view='template') return widget_config
def compact_javascript_files(): print " " print "Processing javascript files to compact into single '_compact_spt_all.js' file ..." print " " context_path = "%s/src/context" % Environment.get_install_dir() all_js_path = js_includes.get_compact_js_filepath() out_fp = open(all_js_path, "w") for (dir, includes_list) in js_includes.all_lists: for include in includes_list: js_path = "%s/%s/%s" % (context_path, dir, include) print " >> processing '%s' ..." % js_path out_fp.write("// %s\n\n" % js_path) in_fp = open(js_path, "r") done = False comment_flag = False while not done: line = in_fp.readline() if not line: done = True continue line = line.strip() if line.startswith("//"): continue start_comment_idx = line.find("/*") if start_comment_idx != -1: comment_flag = True tmp_line = line[:start_comment_idx].strip() if tmp_line: out_fp.write("%s\n" % tmp_line) if line.find("*/") != -1: comment_flag = False tmp_line = line[line.find("*/") + 2:].strip() if tmp_line: out_fp.write("%s\n" % tmp_line) continue if comment_flag: continue line = line.strip() if line: out_fp.write("%s\n" % line) in_fp.close() out_fp.write("\n\n") out_fp.close() print " " print "Generated compact '%s' file." % all_js_path print " " print "DONE compacting javascript files into single file." print " "
def compact_javascript_files(): print " " print "Processing javascript files to compact into single '_compact_spt_all.js' file ..." print " " context_path = "%s/src/context" % Environment.get_install_dir() all_js_path = js_includes.get_compact_js_filepath() out_fp = open( all_js_path, "w" ) for (dir, includes_list) in js_includes.all_lists: for include in includes_list: js_path = "%s/%s/%s" % (context_path, dir, include) print " >> processing '%s' ..." % js_path out_fp.write( "// %s\n\n" % js_path ) in_fp = open( js_path, "r" ) done = False comment_flag = False while not done: line = in_fp.readline() if not line: done = True continue line = line.strip() if line.startswith("//"): continue start_comment_idx = line.find( "/*" ) if start_comment_idx != -1: comment_flag = True tmp_line = line[ : start_comment_idx ].strip() if tmp_line: out_fp.write( "%s\n" % tmp_line ) if line.find( "*/" ) != -1: comment_flag = False tmp_line = line[ line.find("*/") + 2 : ].strip() if tmp_line: out_fp.write( "%s\n" % tmp_line ) continue if comment_flag: continue line = line.strip() if line: out_fp.write( "%s\n" % line ) in_fp.close() out_fp.write( "\n\n" ) out_fp.close() print " " print "Generated compact '%s' file." % all_js_path print " " print "DONE compacting javascript files into single file." print " "
def get_file_contents(version_filename): env = Environment() install_dir = env.get_install_dir() path = '/src/client/tactic_client_lib' fullPath = install_dir + path + '/' + version_filename f = open(fullPath, 'r') version_string = f.read() f.close() return version_string
def execute(self): self.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: self.configure_db() self.configure_install() self.configure_mail_services() self.configure_gen_services() self.configure_asset_dir() self.configure_palette() self.configure_security() except Exception as e: raise TacticException('Error in [%s]: %s' % (self.section, e.__str__())) # FIXME: if this all fails, then revert back self.save_config() # after saving the config, test the database self.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) self.restart_program()
def execute(self): self.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: self.configure_db() self.configure_install() self.configure_mail_services() self.configure_gen_services() self.configure_asset_dir() self.configure_palette() self.configure_security() except Exception as e: raise TacticException('Error in [%s]: %s'%(self.section, e.__str__())) # FIXME: if this all fails, then revert back self.save_config() # after saving the config, test the database self.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) self.restart_program()
def color_exists(color): # find the base path tactic_base = Environment.get_install_dir() basedir = "%s/src/context/ui_proto/roundcorners/rc_%s" % (tactic_base, color.replace("#", "")) # print "test for corner: ", color if os.path.exists(basedir): return True else: return False
def color_exists(color): # find the base path tactic_base = Environment.get_install_dir() basedir = "%s/src/context/ui_proto/roundcorners/rc_%s" % (tactic_base, color.replace("#", "")) #print "test for corner: ", color if os.path.exists(basedir): return True else: return False
def get_display(my): alias = my.kwargs.get("alias") my.rel_path = my.kwargs.get("rel_path") if not my.rel_path: from tactic_client_lib import TacticServerStub server = TacticServerStub.get(protocol="local") my.rel_path = server.get_doc_link(alias) if not my.rel_path or my.rel_path == "none_found": # raise TacticException("Help alias [%s] does not exist" % alias) layout = DivWdg() layout.add(HelpCreateWdg(alias=alias)) layout.add(HelpDocFilterWdg(alias="main")) return layout # special condition for plugins path if my.rel_path.startswith("/plugins/"): plugin_dir = Environment.get_plugin_dir() rel_path = my.rel_path.replace("/plugins/", "") path = "%s/%s" % (plugin_dir, rel_path) elif my.rel_path.startswith("/builtin_plugins/"): plugin_dir = Environment.get_builtin_plugin_dir() rel_path = my.rel_path.replace("/builtin_plugins/", "") path = "%s/%s" % (plugin_dir, rel_path) elif my.rel_path.startswith("/assets/"): asset_dir = Environment.get_asset_dir() rel_path = my.rel_path.replace("/assets/", "") path = "%s/%s" % (asset_dir, rel_path) else: # see if there is an override doc_dir = os.environ.get("TACTIC_DOC_DIR") if not doc_dir: doc_dir = Config.get_value("install", "doc_dir") if not doc_dir: install_dir = Environment.get_install_dir() doc_dir = "%s/doc" % install_dir path = "%s/%s" % (doc_dir, my.rel_path) html = [] try: f = open(path, "r") count = 0 for line in f: line = my.filter_line(line, count) html.append(line) count += 1 f.close() except Exception, e: print "Error processing: ", e html.append("Error processing document: %s<br/><br/>" % str(e))
def print_file_location_msg(): env = Environment() install_dir = env.get_install_dir() print ' The version files are located here:' print ' %s/VERSION' % install_dir print ' %s/src/context/VERSION' % install_dir print ' %s/src/client/tactic_client_lib/VERSION' % install_dir print ' %s/src/pyasm/application/common/interpreter/tactic_client_lib/VERSION' % install_dir print '' print ' The client tactic.zip is located here:' print ' %s/src/client/tactic_client_lib/tactic.zip' % install_dir
def get_display(my): alias = my.kwargs.get("alias") my.rel_path = my.kwargs.get("rel_path") if not my.rel_path: from tactic_client_lib import TacticServerStub server = TacticServerStub.get(protocol='local') my.rel_path = server.get_doc_link(alias) if not my.rel_path or my.rel_path == 'none_found': #raise TacticException("Help alias [%s] does not exist" % alias) layout = DivWdg() layout.add(HelpCreateWdg(alias=alias)) layout.add(HelpDocFilterWdg(alias='main')) return layout # special condition for plugins path if my.rel_path.startswith("/plugins/"): plugin_dir = Environment.get_plugin_dir() rel_path = my.rel_path.replace("/plugins/", "") path = "%s/%s" % (plugin_dir, rel_path) elif my.rel_path.startswith("/builtin_plugins/"): plugin_dir = Environment.get_builtin_plugin_dir() rel_path = my.rel_path.replace("/builtin_plugins/", "") path = "%s/%s" % (plugin_dir, rel_path) elif my.rel_path.startswith("/assets/"): asset_dir = Environment.get_asset_dir() rel_path = my.rel_path.replace("/assets/", "") path = "%s/%s" % (asset_dir, rel_path) else: # see if there is an override doc_dir = os.environ.get("TACTIC_DOC_DIR") if not doc_dir: doc_dir = Config.get_value("install", "doc_dir") if not doc_dir: install_dir = Environment.get_install_dir() doc_dir = "%s/doc" % install_dir path = "%s/%s" % (doc_dir, my.rel_path) html = [] try: f = open(path, 'r') count = 0 for line in f: line = my.filter_line(line, count) html.append(line) count += 1 f.close() except Exception, e: print "Error processing: ", e html.append("Error processing document: %s<br/><br/>" % str(e))
def generate(color): # find the base path tactic_base = Environment.get_install_dir() basedir = "%s/src/context/ui_proto/roundcorners/rc_%s" % (tactic_base, color.replace("#", "")) basename = "rc_%s_10x10" % color cmd = CornerGenerator(color=color, basedir=basedir, basename=basename) cmd.execute() basename = "rc_%s_5x5" % color cmd = CornerGenerator(color=color, basedir=basedir, basename=basename, size=5) cmd.execute()
def upgrade(): print("Running upgrade on 'sthpw' database") install_dir = Environment.get_install_dir() python = Common.get_python() cmd = "%s %s/src/bin/upgrade_db.py -q -f -y -p sthpw" % (python, install_dir) print(cmd) os.system(cmd)
def upgrade(): print "Running upgrade on 'sthpw' database" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" cmd = "%s %s/src/bin/upgrade_db.py -f -y -p sthpw" % (python, install_dir) print cmd os.system(cmd)
def upgrade(): print "Running upgrade on 'sthpw' database" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" cmd = "%s \"%s/src/bin/upgrade_db.py\" -f -y -p sthpw" % (python, install_dir) print cmd os.system(cmd)
def init(my): install_dir = Environment.get_install_dir() # initialize js = ''' <!-- TACTIC --> // Fixes var spt = {}; spt.browser = {}; spt.browser.is_IE = function() { return false; } spt.error = function(error) { throw(error); } ''' my.ctx.eval(js) sources = [ "environment.js", "client_api.js" ] for source in sources: #path = "tactic/%s" % source path = "%s/src/context/spt_js/%s" % (install_dir, source) js = open(path).read() my.ctx.eval(js) js = ''' spt._delegate = function(func_name, args, kwargs) { // convert everything to json var args2 = []; for (var i in args) { args2.push(args[i]); } if (typeof(kwargs) == "undefined") { kwargs = {}; } args2 = JSON.stringify(args2); kwargs = JSON.stringify(kwargs); var ret_val = spt_delegator.execute(func_name, args2, kwargs); ret_val = JSON.parse(ret_val); return ret_val; } var server = TacticServerStub.get(); ''' my.ctx.eval(js)
def execute(my): # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) my.configure_db() my.configure_install() my.configure_services() my.configure_asset_dir() my.configure_palette() # FIXME: if this all fails, then revert back my.save_config() # after saving the config, test the database my.load_bootstrap() # remove the first run file data_dir = Environment.get_data_dir() path = "%s/first_run" % data_dir if os.path.exists(path): os.unlink(path) my.restart_program()
def upgrade(): print "Running upgrade on 'sthpw' database" install_dir = Environment.get_install_dir() from pyasm.common import Config python = Config.get_value("services", "python") if not python: python = "python" cmd = '%s "%s/src/bin/upgrade_db.py" -f -y -p sthpw' % (python, install_dir) print cmd os.system(cmd)
def init(self): install_dir = Environment.get_install_dir() # initialize js = ''' <!-- TACTIC --> // Fixes var spt = {}; spt.browser = {}; spt.browser.is_IE = function() { return false; } spt.error = function(error) { throw(error); } ''' self.ctx.eval(js) sources = ["environment.js", "client_api.js"] for source in sources: #path = "tactic/%s" % source path = "%s/src/context/spt_js/%s" % (install_dir, source) js = open(path).read() self.ctx.eval(js) js = ''' spt._delegate = function(func_name, args, kwargs) { // convert everything to json var args2 = []; for (var i in args) { args2.push(args[i]); } if (typeof(kwargs) == "undefined") { kwargs = {}; } args2 = JSON.stringify(args2); kwargs = JSON.stringify(kwargs); var ret_val = spt_delegator.execute(func_name, args2, kwargs); ret_val = JSON.parse(ret_val); return ret_val; } var server = TacticServerStub.get(); ''' self.ctx.eval(js)
def get_md5(path): '''get md5 checksum''' py_exec = Config.get_value("services", "python") if not py_exec: py_exec = "python" popen = subprocess.Popen([py_exec, '%s/src/bin/get_md5.py'%Environment.get_install_dir(), path], shell=False, stdout=subprocess.PIPE) popen.wait() output = '' value = popen.communicate() if value: output = value[0].strip() if not output: err = value[1] print err return output
def upgrade(my): project_code = my.kwargs.get('project_code') # run the upgrade script (this has to be done in a separate # process due to possible sql errors in a transaction install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" impl = Project.get_database_impl() from pyasm.search.upgrade import Upgrade version = Environment.get_release_version() version.replace('.', '_') upgrade = Upgrade(version, is_forced=True, project_code=project_code, quiet=True) upgrade.execute()
def import_schema(plugin_code): from pyasm.search import Transaction transaction = Transaction.get(create=True) install_dir = Environment.get_install_dir() base_dir = Environment.get_plugin_dir() template_dir = "%s/%s" % (base_dir, plugin_code) manifest_path = "%s/manifest.xml" % (template_dir) print "Reading manifest: ", manifest_path xml = Xml() xml.read_file(manifest_path) # create a new project installer = PluginInstaller(base_dir=base_dir, manifest=xml.to_string() ) installer.execute()
def import_schema(plugin_code): from pyasm.search import Transaction transaction = Transaction.get(create=True) install_dir = Environment.get_install_dir() base_dir = Environment.get_plugin_dir() template_dir = "%s/%s" % (base_dir, plugin_code) manifest_path = "%s/manifest.xml" % (template_dir) print "Reading manifest: ", manifest_path xml = Xml() xml.read_file(manifest_path) # create a new project installer = PluginInstaller(base_dir=base_dir, manifest=xml.to_string()) installer.execute()
def get_display(my): if not my.html_file: return "" utility_path = "%s/src/context/utility" % Environment.get_install_dir() html_templates_path = "%s/templates" % utility_path custom_template_path = "%s/site_custom" % utility_path if my.content_type == 'title': return my.page_title elif my.content_type == 'body': body_template_fp = open( "%s/print_custom_page_TEMPLATE_body_contents.html" % html_templates_path, "r") body_template = body_template_fp.read() body_template_fp.close() layout_html_fp = open( "%s/%s" % (custom_template_path, my.html_file), "r") layout_html = layout_html_fp.read() layout_html_fp.close() layout_bits = layout_html.split("[[DATA_GATHER]]") layout_html = "%s%s" % (layout_bits[0], layout_bits[2]) stmt = layout_bits[1].strip() stmt_bits = stmt.split("\n") stmt_arr = [] for s in stmt_bits: stmt_arr.append(s.strip()) stmt = '\n'.join(stmt_arr) exec stmt # assigns 'gather_specs' dictionary ... layout_html_filled = my.process_data_gather( my.search_key, gather_specs, layout_html) body_html = body_template.replace("[[PRINT_LAYOUT_PLACEHOLDER]]", layout_html_filled) return body_html return "" # FIXME: should error or return some error message
def set_string_in_version_file(pathList, version_filename, version_string): print '--' print print ' Updating string to "%s" in version file: %s ' % (version_string, version_filename) print env = Environment() install_dir = env.get_install_dir() pathCount = len(pathList) for index, path in enumerate(pathList): fullPath = install_dir + path + '/' + version_filename f = open(fullPath, 'w') print ' Output: %i of %i - Writing %s to:' % (index+1, pathCount, version_filename) print ' %s' % fullPath # Write the give command line argument as the version string in the file. f.write(version_string) print ' - Done. Closing file.' f.close() print ''
def get_md5(path): '''get md5 checksum''' py_exec = Config.get_value("services", "python") if not py_exec: py_exec = "python" if isinstance(path, unicode): path = path.encode('utf-8') popen = subprocess.Popen([py_exec, '%s/src/bin/get_md5.py'%Environment.get_install_dir(), path], shell=False, stdout=subprocess.PIPE) popen.wait() output = '' value = popen.communicate() if value: output = value[0].strip() if not output: err = value[1] print err return output
def execute(my): my.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: my.configure_db() my.configure_install() my.configure_mail_services() my.configure_gen_services() my.configure_asset_dir() my.configure_palette() my.configure_security() except Exception, e: raise TacticException('Error in [%s]: %s' % (my.section, e.__str__()))
def execute(my): # check to see the status of this job """ job = my.kwargs.get('job') job_code = job.get_code() search = Search("sthpw/queue") search.add_filter("code", job_code) my.kwargs['job'] = search.get_sobject() if not job: print "Cancelling ..." return state = job.get_value("state") if state == "cancel": print "Cancelling 2 ...." return """ subprocess_kwargs = { 'login': login, 'project_code': project_code, 'command': command, 'kwargs': kwargs } subprocess_kwargs_str = jsondumps(subprocess_kwargs) install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = 'python' args = [ '%s' % python, '%s/src/tactic/command/queue.py' % install_dir ] args.append(subprocess_kwargs_str) import subprocess p = subprocess.Popen(args) DbContainer.close_thread_sql() return
def get_display(self): if not self.html_file: return "" utility_path = "%s/src/context/utility" % Environment.get_install_dir() html_templates_path = "%s/templates" % utility_path custom_template_path = "%s/site_custom" % utility_path if self.content_type == 'title': return self.page_title elif self.content_type == 'body': body_template_fp = open( "%s/print_custom_page_TEMPLATE_body_contents.html" % html_templates_path, "r" ) body_template = body_template_fp.read() body_template_fp.close() layout_html_fp = open( "%s/%s" % (custom_template_path, self.html_file), "r" ) layout_html = layout_html_fp.read() layout_html_fp.close() layout_bits = layout_html.split("[[DATA_GATHER]]") layout_html = "%s%s" % (layout_bits[0], layout_bits[2]) stmt = layout_bits[1].strip() stmt_bits = stmt.split("\n") stmt_arr = [] for s in stmt_bits: stmt_arr.append( s.strip() ) stmt = '\n'.join( stmt_arr ) exec stmt # assigns 'gather_specs' dictionary ... layout_html_filled = self.process_data_gather( self.search_key, gather_specs, layout_html ) body_html = body_template.replace("[[PRINT_LAYOUT_PLACEHOLDER]]", layout_html_filled) return body_html return "" # FIXME: should error or return some error message
def set_string_in_version_file(pathList, version_filename, version_string): print '--' print print ' Updating string to "%s" in version file: %s ' % (version_string, version_filename) print env = Environment() install_dir = env.get_install_dir() pathCount = len(pathList) for index, path in enumerate(pathList): fullPath = install_dir + path + '/' + version_filename f = open(fullPath, 'w') print ' Output: %i of %i - Writing %s to:' % (index + 1, pathCount, version_filename) print ' %s' % fullPath # Write the give command line argument as the version string in the file. f.write(version_string) print ' - Done. Closing file.' f.close() print ''
def load_bootstrap(my): impl = DatabaseImpl.get() exists = impl.database_exists("sthpw") print "exists: ", exists vendor = impl.get_database_type() if not exists: print "Running bootstrap" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" # create the database and inject the bootstrap data impl.create_database("sthpw") cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (python, install_dir, vendor.lower()) os.system(cmd)
def execute(my): my.section = None # make sure tmp config is unset. Config.unset_tmp_config() Config.reload_config() web = WebContainer.get_web() # read the current config file. # copy config to the path config_path = Config.get_config_path() if not os.path.exists(config_path): print "Installing default config file" dirname = os.path.dirname(config_path) if not os.path.exists(dirname): os.makedirs(dirname) if os.name == 'nt': osname = 'win32' else: osname = 'linux' install_dir = Environment.get_install_dir() install_config_path = "%s/src/install/start/config/tactic_%s-conf.xml" % ( install_dir, osname) shutil.copy(install_config_path, dirname) try: my.configure_db() my.configure_install() my.configure_mail_services() my.configure_gen_services() my.configure_asset_dir() my.configure_palette() my.configure_security() except Exception, e: raise TacticException('Error in [%s]: %s'%(my.section, e.__str__()))
def load_bootstrap(my): impl = DatabaseImpl.get() exists = impl.database_exists("sthpw") print "exists: ", exists vendor = impl.get_database_type() if not exists: print "Running bootstrap" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" # create the database and inject the bootstrap data impl.create_database("sthpw") cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % ( python, install_dir, vendor.lower()) os.system(cmd)
def get_display(self): widget = Widget() web = WebContainer.get_web() args = web.get_form_args() search_type = args['search_type'] search_id = args['search_id'] project = Search.get_by_id(search_type, search_id) #project = self.sobject project_code = project.get_code() project_type = project.get_type() widget.add("<h3>Summary: %s</h3>" % project_code) last_db_update = project.get_value("last_db_update") widget.add("Last Database Update: %s" % last_db_update) install_dir = Environment.get_install_dir() summary_exec = "%s/src/pyasm/search/upgrade/summary.py" % install_dir cmd = 'python "%s" %s %s' % (summary_exec, project_code, project_type) pre = self.get_results_wdg(cmd) widget.add(pre) if project_type == "prod": pass elif project_type == "flash": pass else: data_exec = "%s/src/pyasm/search/upgrade/data_summary.py" % install_dir for table in ['search_object', 'notification']: cmd = 'python "%s" %s %s %s' % (data_exec, project_code, project_type, table) print cmd pre = self.get_results_wdg(cmd) widget.add(pre) return widget
def execute(self): # check to see the status of this job """ job = self.kwargs.get('job') job_code = job.get_code() search = Search("sthpw/queue") search.add_filter("code", job_code) self.kwargs['job'] = search.get_sobject() if not job: print("Cancelling ...") return state = job.get_value("state") if state == "cancel": print("Cancelling 2 ....") return """ subprocess_kwargs = { 'login': login, 'project_code': project_code, 'command': command, 'kwargs': kwargs } subprocess_kwargs_str = jsondumps(subprocess_kwargs) install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = 'python' args = ['%s' % python, '%s/src/tactic/command/queue.py' % install_dir] args.append(subprocess_kwargs_str) import subprocess p = subprocess.Popen(args) DbContainer.close_thread_sql() return
def get_compact_js_filepath(): all_js_path = "%s/src/context/%s" % \ ( Environment.get_install_dir(), get_compact_js_context_path_suffix() ) return all_js_path
def configure_db(my): my.section = 'Database Setup' web = WebContainer.get_web() vendor = web.get_form_value("database/vendor") if not vendor: raise TacticException("A vendor needs to be passed in.") if vendor == 'Sqlite': # take the current files and copy them to the database folder db_dir = web.get_form_value("database/sqlite_db_dir") if not db_dir: raise TacticException( "No Folder configured for Sqlite Database") if not os.path.exists(db_dir): os.makedirs(db_dir) # check to see if the sthpw database is in this folder sthpw_path = "%s/sthpw.db" % (db_dir) if not os.path.exists(sthpw_path): # copy the default database over install_dir = Environment.get_install_dir() template_db = "%s/src/install/start/db/sthpw.db" % install_dir shutil.copy(template_db, db_dir) Config.set_value("database", "sqlite_db_dir", db_dir) Config.remove("database", "server") Config.remove("database", "port") Config.remove("database", "user") Config.remove("database", "password") else: defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] Config.remove("database", "sqlite_db_dir") if vendor == 'MySQL': default_encoding = defaults['encoding'] default_charset = defaults['charset'] encoding = web.get_form_value("encoding") if not encoding: encoding = default_encoding if encoding: Config.set_value("database", "encoding", encoding) else: Config.set_value("database", "encoding", "") charset = web.get_form_value("charset") if not charset: charset = default_charset if charset: Config.set_value("database", "charset", charset) else: Config.set_value("database", "charset", "") # get the info server = web.get_form_value("server") if not server: server = default_server port = web.get_form_value("port") if not port: port = default_port else: port = int(port) user = web.get_form_value("user") if not user: user = default_user password = web.get_form_value("password") if not password: password = default_password if server: Config.set_value("database", "server", server) else: #Config.remove("database", "server") Config.set_value("database", "server", "") if port: Config.set_value("database", "port", port) else: #Config.remove("database", "port") Config.set_value("database", "port", "") if user: Config.set_value("database", "user", user) else: #Config.remove("database", "user") Config.set_value("database", "user", "") if password: Config.set_value("database", "password", password) else: Config.set_value("database", "password", "") #Config.remove("database", "password") # save the database Config.set_value("database", "vendor", vendor)
def configure_db(my): web = WebContainer.get_web() vendor = web.get_form_value("database/vendor") if vendor == 'Sqlite': # take the current files and copy them to the database folder db_dir = web.get_form_value("database/sqlite_db_dir") if not db_dir: raise TacticException("No Folder configured for Sqlite Database") if not os.path.exists(db_dir): os.makedirs(db_dir) # check to see if the sthpw database is in this folder sthpw_path = "%s/sthpw.db" % (db_dir) if not os.path.exists(sthpw_path): # copy the default database over install_dir = Environment.get_install_dir() template_db = "%s/src/install/start/db/sthpw.db" % install_dir shutil.copy(template_db, db_dir) Config.set_value("database", "sqlite_db_dir", db_dir) Config.remove("database", "server") Config.remove("database", "port") Config.remove("database", "user") Config.remove("database", "password") else: defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] Config.remove("database", "sqlite_db_dir") # get the info server = web.get_form_value("server") if not server: server = default_server port = web.get_form_value("port") if not port: port = default_port else: port = int(port) user = web.get_form_value("user") if not user: user = default_user password = web.get_form_value("password") if not password: password = default_password if server: Config.set_value("database", "server", server) else: #Config.remove("database", "server") Config.set_value("database", "server", "") if port: Config.set_value("database", "port", port) else: #Config.remove("database", "port") Config.set_value("database", "port", "") if user: Config.set_value("database", "user", user) else: #Config.remove("database", "user") Config.set_value("database", "user", "") if password: Config.set_value("database", "password", password) else: Config.set_value("database", "password", "") #Config.remove("database", "password") # save the database Config.set_value("database", "vendor", vendor)
def test_postgres(my, vendor): web = WebContainer.get_web() defaults = DEFAULTS[vendor] default_server = defaults['server'] default_port = defaults['port'] default_user = defaults['user'] default_password = defaults['password'] server = web.get_form_value("server") if not server: server = default_server port = web.get_form_value("port") if not port: port = default_port else: port = int(port) user = web.get_form_value("user") if not user: user = default_user password = web.get_form_value("password") if not password: password = default_password # Need to access remote database create = False impl = DatabaseImpl.get(vendor) exists = impl.database_exists("sthpw", host=server, port=port) if not create: if not exists: my.info['error'] = "Database [sthpw] does not exist. This is required for TACTIC to function." return else: print "Running bootstrap" install_dir = Environment.get_install_dir() python = Config.get_value("services", "python") if not python: python = "python" # create the database and inject the bootstrap data impl.create_database("sthpw", host=server, port=port) cmd = "%s %s/src/pyasm/search/upgrade/%s/bootstrap_load.py" % (python, install_dir, vendor.lower()) os.system(cmd) from pyasm.search import Sql sql = Sql("sthpw", server, user, password=password, vendor=vendor, port=port) try: # attempt sql.connect() sql.do_query("select id from transaction_log limit 1") except Exception, e: my.info['error'] = "Could not connect to database with (vendor=%s, server=%s, user=%s, port=%s)" % (vendor, server, user, port) my.info['message'] = str(e) print e
def register_site(my, site, config): # if there happend to be . in the site name, convert to _ site = site.replace(".", "_") if site == "template": return print "Registering project ... %s" % site try: from tactic.ui.app import SitePage exec("cherrypy.root.tactic.%s = SitePage()" % site) exec("cherrypy.root.projects.%s = SitePage()" % site) except ImportError: #print "... WARNING: SitePage not found" exec("cherrypy.root.tactic.%s = TacticIndex()" % site) exec("cherrypy.root.projects.%s = TacticIndex()" % site) except SyntaxError: print "WARNING: skipping project [%s]" % site # The rest is only ever executed on the "default" site # This is to get admin site working if site in ['admin', 'default', 'template', 'unittest']: base = "tactic_sites" else: base = "sites" # get the contexts: if site in ("admin", "default", "template", "unittest"): context_dir = Environment.get_install_dir().replace("\\", "/") context_dir = "%s/src/tactic_sites/%s/context" % (context_dir, site) else: context_dir = Environment.get_site_dir().replace("\\", "/") context_dir = "%s/sites/%s/context" % (context_dir, site) if not os.path.exists(context_dir): return contexts = [] for context_dir in os.listdir(context_dir): if not context_dir.endswith(".py"): continue if context_dir == "__init__.py": continue if context_dir.startswith("."): continue if os.path.isdir(context_dir): continue context = context_dir.replace(".py", "") contexts.append(context) for context in contexts: try: exec("from %s.%s.context.%s import %s" % (base, site, context, context)) exec("cherrypy.root.tactic.%s.%s = %s()" % (site, context, context)) except ImportError, e: print str(e) print "... failed to import '%s.%s.%s'" % (base, site, context) raise #return path = "/tactic/%s/%s" % (site, context) settings = {} config[path] = settings if context in ["XMLRPC", "Api"]: #settings['request.dispatch'] = cherrypy.dispatch.XMLRPCDispatcher(), settings['tools.xmlrpc.on'] = True settings['tools.xmlrpc.encoding'] = 'utf-8' settings['tools.xmlrpc.allow_none'] = True
# The rest is only ever executed on the "default" project # This is to get admin project working if project in ['admin', 'default', 'template', 'unittest']: base = "tactic_sites" else: base = "sites" # get the contexts: if project in ("admin", "default", "template", "unittest"): context_dir = Environment.get_install_dir().replace("\\", "/") context_dir = "%s/src/tactic_sites/%s/context" % (context_dir, project) else: context_dir = Environment.get_site_dir().replace("\\", "/") context_dir = "%s/sites/%s/context" % (context_dir, project) if not os.path.exists(context_dir): return contexts = [] for context_dir in os.listdir(context_dir): if not context_dir.endswith(".py"): continue if context_dir == "__init__.py":
def get_display(my): alias = my.kwargs.get("alias") my.rel_path = my.kwargs.get("rel_path") if not my.rel_path: from tactic_client_lib import TacticServerStub server = TacticServerStub.get(protocol='local') my.rel_path = server.get_doc_link(alias) if not my.rel_path or my.rel_path == 'none_found': #raise TacticException("Help alias [%s] does not exist" % alias) layout = DivWdg() layout.add(HelpCreateWdg(alias=alias)) layout.add(HelpDocFilterWdg(alias='main')) return layout # special condition for plugins path if my.rel_path.startswith("/plugins/"): plugin_dir = Environment.get_plugin_dir() rel_path = my.rel_path.replace("/plugins/", "") path = "%s/%s" % (plugin_dir,rel_path) elif my.rel_path.startswith("/builtin_plugins/"): plugin_dir = Environment.get_builtin_plugin_dir() rel_path = my.rel_path.replace("/builtin_plugins/", "") path = "%s/%s" % (plugin_dir,rel_path) elif my.rel_path.startswith("/assets/"): asset_dir = Environment.get_asset_dir() rel_path = my.rel_path.replace("/assets/", "") path = "%s/%s" % (asset_dir,rel_path) else: # see if there is an override doc_dir = os.environ.get("TACTIC_DOC_DIR") if not doc_dir: doc_dir = Config.get_value("install", "doc_dir") if not doc_dir: install_dir = Environment.get_install_dir() doc_dir = "%s/doc" % install_dir path = "%s/%s" % (doc_dir, my.rel_path) html = [] try: paths = path.split('#') anchor = '' if len(paths) > 1: anchor = paths[-1] path = paths[0] read = False else: read = True f = open(path, 'r') count = 0 idx = 0 anchor_str = '<a id="%s"></a>'%anchor div_str = '<div class="titlepage">' strip_count = 0 for line in f: if anchor and not read: tmp_line = line.decode('utf-8','ignore') div_idx = tmp_line.find(div_str) idx = tmp_line.find(anchor_str) if idx != -1: # use the div above the anchor line = line[div_idx:-1] # in case it doesn't get it right on while strip_count < 30 and not line.startswith('<div class="titlepage">'): line = line[1:-1] strip_count += 1 read = True if read: line = my.filter_line(line, count) html.append(line) count += 1 f.close() except Exception, e: print "Error processing: ", e html.append("Error processing document: %s<br/><br/>" % str(e))
def copy_start(self): data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) # create the dist folder to_dir = "%s/dist" % (data_dir) if not os.path.exists(to_dir): os.makedirs(to_dir) # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir, filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True # insert the plugin path to run get_asset_dir() plugin_dir = Environment.get_plugin_dir() sys.path.insert(0, plugin_dir) asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
def register_site(my, site, config): print "Registering project ... %s" % site # if there happend to be . in the site name, convert to _ # NOTE: not sure what the implication of that is??? site = site.replace(".", "_") if site == "template": return # BIG HACK to get admin site working if site in ['admin', 'default', 'template', 'unittest']: base = "tactic_sites" else: base = "sites" try: #exec("from %s.%s.context.Index import Index" % (base,site) ) #exec("cherrypy.root.tactic.%s = Index()" % site) #exec("cherrypy.root.projects.%s = Index()" % site) from tactic.ui.app import SitePage exec("cherrypy.root.tactic.%s = SitePage()" % site) exec("cherrypy.root.projects.%s = SitePage()" % site) except ImportError: #print "... WARNING: Index not found" exec("cherrypy.root.tactic.%s = TacticIndex()" % site) exec("cherrypy.root.projects.%s = TacticIndex()" % site) # get the contexts: if site in ("admin", "default", "template", "unittest"): context_dir = Environment.get_install_dir().replace("\\", "/") context_dir = "%s/src/tactic_sites/%s/context" % (context_dir, site) else: context_dir = Environment.get_site_dir().replace("\\", "/") context_dir = "%s/sites/%s/context" % (context_dir, site) if not os.path.exists(context_dir): #print "WARNING: context directory not found" return contexts = [] for context_dir in os.listdir(context_dir): if not context_dir.endswith(".py"): continue if context_dir == "__init__.py": continue if context_dir.startswith("."): continue if os.path.isdir(context_dir): continue context = context_dir.replace(".py", "") contexts.append(context) for context in contexts: try: exec("from %s.%s.context.%s import %s" % (base, site, context, context)) exec("cherrypy.root.tactic.%s.%s = %s()" % (site, context, context)) except ImportError, e: print str(e) print "... failed to import '%s.%s.%s'" % (base, site, context) raise #return path = "/tactic/%s/%s" % (site, context) settings = {} config[path] = settings if context in ["XMLRPC", "Api"]: settings['xmlrpc_filter.on'] = True # NOTE: is this needed anymore? if context in ["UploadServer"]: settings['flashwrapper.on'] = True
def setup_sites(my): context_path = "%s/src/context" % my.install_dir doc_dir = "%s/doc" % my.install_dir log_dir = "%s/log" % Environment.get_tmp_dir() config = { 'global': { 'server.socket_host': 'localhost', 'server.socket_port': 80, 'server.log_to_screen': False, 'server.environment': 'production', 'server.show_tracebacks': True, 'server.log_request_headers': True, 'server.log_file': "%s/tactic_log" % log_dir, 'server.max_request_body_size': 0, #'server.socket_timeout': 60, 'response.timeout': 3600, 'log_debug_info_filter.on': False, #'encoding_filter.on': True, #'decoding_filter.on': True, }, '/context': { 'static_filter.on': True, 'static_filter.dir': context_path }, '/assets': { 'static_filter.on': True, 'static_filter.dir': Environment.get_asset_dir() }, '/doc': { 'static_filter.on': True, 'static_filter.dir': doc_dir }, '/doc/': { 'static_filter.on': True, 'static_filter.file': "%s/index.html" % doc_dir }, } # set up the root directory cherrypy.root = Root() from tactic_sites.default.context.TitlePage import TitlePage cherrypy.root.tactic = TitlePage() cherrypy.root.projects = TitlePage() sites = [] # add the tactic projects install_dir = Environment.get_install_dir().replace("\\", "/") site_dir = "%s/src/tactic_sites" % install_dir for context_dir in os.listdir(site_dir): if context_dir.startswith(".svn"): continue full_path = "%s/%s" % (site_dir, context_dir) if os.path.isdir(full_path): sites.append(context_dir) # add all the custom projects site_dir = Environment.get_site_dir().replace("\\", "/") site_dir = "%s/sites" % site_dir for context_dir in os.listdir(site_dir): if context_dir.startswith(".svn"): continue full_path = "%s/%s" % (site_dir, context_dir) if os.path.isdir(full_path): sites.append(context_dir) for site in sites: my.register_site(site, config) # set up the images directory for subdir in ['images', 'doc']: config["/tactic/%s/%s/" % (site,subdir)] = { 'static_filter.on': True, 'static_filter.dir': '%s/sites/%s/context/%s/' % \ (site_dir,site, subdir) } return config
def copy_start(my): #import pdb; pdb.set_trace() data_dir = Environment.get_data_dir(manual=True) # check to see if the data folder already exists print print "Data Directory [%s]" % data_dir install_dir = Environment.get_install_dir() # find criteria for initializing initialize = False if data_dir and not os.path.exists(data_dir): initialize = True if data_dir and not os.path.exists("%s/config" % data_dir): initialize = True if initialize: # copy the template over. This should exist even if it is not used print "... not found: initializing\n" install_data_path = "%s/src/install/start" % (install_dir) if os.path.exists(install_data_path): dirnames = os.listdir(install_data_path) for dirname in dirnames: to_dir = "%s/%s" % (data_dir, dirname) if os.path.exists(to_dir): print "WARNING: path [%s] exists ... skipping copying" % to_dir continue print "Copying to [%s]" % to_dir from_dir = "%s/%s" % (install_data_path, dirname) shutil.copytree(from_dir, to_dir) else: shutil.copytree(install_data_path, data_dir) #import pdb; pdb.set_trace() # copy the appropriate config file if os.name == 'nt': filename = 'standalone_win32-conf.xml' else: filename = 'standalone_linux-conf.xml' install_config_path = "%s/src/install/config/%s" % (install_dir,filename) to_config_path = "%s/config/tactic-conf.xml" % data_dir if not os.path.exists(to_config_path): dirname = os.path.dirname(to_config_path) if not os.path.exists(dirname): os.makedirs(dirname) shutil.copy(install_config_path, to_config_path) # some backwards compatibility issues old_config_path = "%s/config/tactic_linux-conf.xml" % data_dir if os.path.exists(old_config_path): new_config_path = "%s/config/tactic-conf.xml" % data_dir shutil.move(old_config_path, new_config_path) config_path = Config.get_config_path() config_exists = False if os.path.exists(config_path): config_exists = True #import pdb; pdb.set_trace() asset_dir = Environment.get_asset_dir() print "Asset Directory [%s]" % asset_dir tmp_dir = Environment.get_tmp_dir() print "Temp Directory [%s]" % tmp_dir # check if there is a config path already exists. If it does, # then don't do anything further. This is likely a previous # installation if config_exists: print "Config_path [%s]" % config_path return else: # if there is no config, retrieve data_dir in non-manual mode data_dir = Environment.get_data_dir() f = open("%s/first_run" % data_dir, 'w') f.write("") f.close() return
def get_display(self): top = DivWdg() top.add_class("spt_sample_chart_top") table = Table() table.add_row() left = table.add_cell() # add the chart chart_div = DivWdg() chart_div.add_class("spt_sample_chart") left.add(chart_div) chart_div.add_style("width: 600") chart_div.add_style("height: 400") chart_div.add_style("padding: 10px") data_file = 'bar-2.txt' chart = ChartWdg(data_file=data_file) chart_div.add(chart) # add navigator right = table.add_cell() right.add_style("text-align: top") top.add(table) base_dir = "%s/src" % Environment.get_install_dir() rel_dir = 'context/spt_js/ofc/data-files' files_div = DivWdg() files_div.add_style("height: 400") files_div.add_style("overflow: auto") files_div.add_style("padding: 3px") right.add(files_div) files = os.listdir("%s/%s" % (base_dir, rel_dir)) for file in files: if not file.endswith(".txt"): continue explore_div = DivWdg() link = "/%s/%s" % (rel_dir, file) explore_div.add( "<a target='_blank' href='%s'>(+)</a> " % link) explore_div.add_style("float: left") files_div.add(explore_div) file_div = DivWdg() file_div.add_style("padding: 2px") file_div.add_class("hand") file_div.add_event("onmouseover", "this.style.background='#696969'") file_div.add_event("onmouseout", "this.style.background='#444'") file_div.add(file) files_div.add(file_div) file_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var value = bvr.src_el.innerHTML; var top = bvr.src_el.getParent(".spt_sample_chart_top"); var chart = top.getElement(".spt_sample_chart"); spt.panel.load(chart, 'tactic.ui.chart.ChartWdg', {data_file:value}); ''' }) return top