def get_display(my): top = my.top unity_wdg = DivWdg() top.add(unity_wdg) unique_id = unity_wdg.set_unique_id("unity") unity_wdg.add("Unity content can't be played. Make sure you are using compatible browser with JavaScript enabled.") #<input id="versionButton" type="button" value="Version" disabled="disabled" onclick="versionButtonClick();" /> # TEST TEST TEST: dynamic loading of js env = Environment.get() install_dir = env.get_install_dir() js_path = "%s/src/context/spt_js/UnityObject.js" % install_dir f = open(js_path) init_js = f.read() f.close() top.add_behavior( { 'type': 'load', 'cbjs_action': ''' %s; %s; ''' % (init_js, my.get_load_js(unique_id) ) } ) return top
def get_display(my): top = my.top unity_wdg = DivWdg() top.add(unity_wdg) unique_id = unity_wdg.set_unique_id("unity") unity_wdg.add( "Unity content can't be played. Make sure you are using compatible browser with JavaScript enabled." ) #<input id="versionButton" type="button" value="Version" disabled="disabled" onclick="versionButtonClick();" /> # TEST TEST TEST: dynamic loading of js env = Environment.get() install_dir = env.get_install_dir() js_path = "%s/src/context/spt_js/UnityObject.js" % install_dir f = open(js_path) init_js = f.read() f.close() top.add_behavior({ 'type': 'load', 'cbjs_action': ''' %s; %s; ''' % (init_js, my.get_load_js(unique_id)) }) return top
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add(my.get_copyright_wdg()) widget.add(html) # create the header head = HtmlElement("head") html.add(head) head.add( '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n' ) head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add( '<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>' ) # add the css styling head.add(my.get_css_wdg()) # add the title in the header project = Project.get() project_code = project.get_code() project_title = project.get_value("title") if web.is_admin_page(): is_admin = " - Admin" else: is_admin = "" if project_code == 'admin': head.add("<title>TACTIC Site Admin</title>\n") else: head.add("<title>%s%s</title>\n" % (project_title, is_admin)) # add the javascript libraries head.add(JavascriptImportWdg()) # add the body body = my.body html.add(body) body.add_event('onload', 'spt.onload_startup(this)') top = my.top # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript' # is not checked ... TODO: clean up and re-style to make look nicer top.add(""" <NOSCRIPT> <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;"> <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b> <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p> </div> </NOSCRIPT> """ % (IconWdg.get_icon_path("ERROR"))) # add the content content_div = DivWdg() top.add(content_div) Container.put("TopWdg::content", content_div) # add a dummy button for global behaviors from tactic.ui.widget import ButtonNewWdg, IconButtonWdg ButtonNewWdg(title="DUMMY", icon=IconWdg.FILM) IconButtonWdg(title="DUMMY", icon=IconWdg.FILM) # NOTE: it does not need to be in the DOM. Just needs to be # instantiated #content_div.add(button) if my.widgets: content_wdg = my.get_widget('content') else: content_wdg = Widget() my.add(content_wdg) content_div.add(content_wdg) # add a calendar wdg from tactic.ui.widget import CalendarWdg cal_wdg = CalendarWdg(css_class='spt_calendar_template_top') cal_wdg.top.add_style('display: none') content_div.add(cal_wdg) if web.is_admin_page(): from tactic_branding_wdg import TacticCopyrightNoticeWdg branding = TacticCopyrightNoticeWdg(show_license_info=True) top.add(branding) # add the admin bar security = Environment.get_security() if not web.is_admin_page() and security.check_access( "builtin", "view_site_admin", "allow"): div = DivWdg() top.add(div) top.add_style("padding-top: 21px") div.add_class("spt_admin_bar") div.add_style("height: 15px") div.add_style("padding: 3px 0px 3px 15px") #div.add_style("margin-bottom: -5px") div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.7") div.add_style("width: 100%") #div.add_gradient("background", "background2", 20, 10) div.add_style("background-color", "#000") div.add_style("color", "#FFF") div.add_style("z-index", "1000") div.add_class("hand") div.set_box_shadow("0px 5px 5px") # remove icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Remove Admin Bar", icon=IconWdg.G_CLOSE) icon_div.add(icon_button) icon_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var parent = bvr.src_el.getParent(".spt_admin_bar"); bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(parent); ''' }) div.add("<b>ADMIN >></b>") div.add_behavior({ 'type': 'listen', 'event_name': 'close_admin_bar', 'cbjs_action': ''' bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(bvr.src_el); ''' }) div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.85) //new Fx.Tween(bvr.src_el).start('height', "30px"); ''' }) div.add_behavior({ 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.7) //new Fx.Tween(bvr.src_el).start('height', "15px"); ''' }) project_code = Project.get_project_code() div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var url = "/tactic/%s/admin/link/_startup"; window.open(url); ''' % project_code }) # Add the script editor listener load_div = DivWdg() top.add(load_div) load_div.add_behavior({ 'type': 'listen', 'event_name': 'show_script_editor', 'cbjs_action': ''' var js_popup_id = "TACTIC Script Editor"; var js_popup = $(js_popup_id); if( js_popup ) { spt.popup.toggle_display( js_popup_id, false ); } else { spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} ); } ''' }) # deal with the palette defined in /index which can override the palette if my.kwargs.get("hash") == (): key = "index" search = Search("config/url") search.add_filter("url", "/%s/%%" % key, "like") search.add_filter("url", "/%s" % key) search.add_where("or") url = search.get_sobject() if url: xml = url.get_xml_value("widget") palette_key = xml.get_value("element/@palette") # look up palette the expression for index from pyasm.web import Palette palette = Palette.get() palette.set_palette(palette_key) colors = palette.get_colors() colors = jsondumps(colors) script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_colors(%s); env.set_palette('%s'); ''' % (colors, palette_key)) top.add(script) env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() login = Environment.get_login() user_name = login.get_value("login") user_id = login.get_id() login_groups = Environment.get_group_names() # add environment information script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_project('%s'); env.set_user('%s'); env.set_user_id('%s'); var login_groups = '%s'.split('|'); env.set_login_groups(login_groups); env.set_client_handoff_dir('%s'); env.set_client_repo_dir('%s'); ''' % (Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir, client_asset_dir)) top.add(script) # add a global container for commonly used widgets div = DivWdg() top.add(div) div.set_id("global_container") # add in the app busy widget # find out if there is an override for this search = Search("config/url") search.add_filter("url", "/app_busy") url = search.get_sobject() if url: busy_div = DivWdg() div.add(busy_div) busy_div.add_class("SPT_PUW") busy_div.add_styles( "display: none; position: absolute; z-index: 1000") busy_div.add_class("app_busy_msg_block") busy_div.add_style("width: 300px") busy_div.add_style("height: 100px") busy_div.add_style("padding: 20px") busy_div.add_color("background", "background3") busy_div.add_border() busy_div.set_box_shadow() busy_div.set_round_corners(20) busy_div.set_attr("id", "app_busy_msg_block") # put the custom url here title_wdg = DivWdg() busy_div.add(title_wdg) title_wdg.add_style("font-size: 20px") title_wdg.add_class("spt_app_busy_title") busy_div.add("<hr/>") msg_div = DivWdg() busy_div.add(msg_div) msg_div.add_class("spt_app_busy_msg") else: from page_header_wdg import AppBusyWdg div.add(AppBusyWdg()) # popup parent popup = DivWdg() popup.set_id("popup") div.add(popup) # create another general popup popup_div = DivWdg() popup_div.set_id("popup_container") popup_div.add_class("spt_panel") popup = PopupWdg(id="popup_template", destroy_on_close=True) popup_div.add(popup) div.add(popup_div) inner_html_div = DivWdg() inner_html_div.set_id("inner_html") div.add(inner_html_div) # add in a global color from tactic.ui.input import ColorWdg color = ColorWdg() div.add(color) # add in a global notify wdg from notify_wdg import NotifyWdg widget.add(NotifyWdg()) return widget
def execute(self): input = self.get_input() search_type = input.get('search_type') if search_type != 'sthpw/transaction_log': print("ERROR: this trigger can only be executed for transaction_logs") return project = Project.get() # Block admin project from syncing # NOTE: maybe need an option to enable this? if project.get_code() == 'admin': return log = input.get('sobject') transaction_code = log.get_value("code") # if this is a remote transaction, then do not create a job for it local_prefix = Config.get_value("install", "server") search = Search("sthpw/sync_server") search.add_filter("state", "online") servers = search.get_sobjects() #print("servers: ", len(servers)) # These are usually determined by the server entry #sync_mode = input.get('mode') #if not sync_mode or sync_mode == 'default': # sync_mode = 'xmlrpc' ## This will transaction into a "file" folder #sync_mode = "file" #file_mode = 'delayed' #file_mode = 'upload' # get some user info env = Environment.get() #user = env.get_user_name() #ticket = env.get_ticket() project_code = Project.get_project_code() from pyasm.security import AccessManager access_manager = AccessManager() for server in servers: # check security #if not self.check_security(server): # print("Transaction denied due to security restrictions") # continue server_code = server.get_code() # don't publish a transaction back to the original server if log.get_value("server_code") == server_code: continue # check project security rules = server.get_value("access_rules"); if not rules: rules = "<rules/>" access_manager.add_xml_rules(rules) # filter based on project code namespace = log.get_value("namespace") key1 = { 'code': namespace } key2 = { 'code': '*' } keys = [key1, key2] if not access_manager.check_access("project", keys, "allow", default="deny"): continue # filter based on transaction key """ keywords = log.get_value("kewords", no_exception=True) key1 = { 'keywords': keywords } key2 = { 'keywords': '*' } keys = [key1, key2] if not access_manager.check_access("transaction", keys, "allow", default="deny"): continue """ # filter out any specific rules from transaction itself from tactic.ui.sync import SyncFilter sync_filter = SyncFilter(rules=rules, transaction=log) sync_filter.execute() filtered_xml = sync_filter.get_filtered_xml() message = sync_filter.get_message() # create a new job entry job = SearchType.create("sthpw/sync_job") job.set_value("state", "pending") job.set_value("server_code", server_code) job.set_value("transaction_code", transaction_code) job.set_user() job.set_value("command", "tactic.command.TransactionQueueCmd") kwargs = { 'server': server.get_value("code"), 'transaction_code': transaction_code, 'project_code': project_code, #'file_mode': file_mode, #'sync_mode': sync_mode } job.set_json_value("data", kwargs) job.commit()
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add( my.get_copyright_wdg() ) widget.add(html) # create the header head = HtmlElement("head") html.add(head) head.add('<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n') head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add('<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>') # add the css styling head.add(my.get_css_wdg()) # add the title in the header project = Project.get() project_code = project.get_code() project_title = project.get_value("title") if web.is_admin_page(): is_admin = " - Admin" else: is_admin = "" if project_code == 'admin': head.add("<title>TACTIC Site Admin</title>\n" ) else: head.add("<title>%s%s</title>\n" % (project_title, is_admin) ) # add the javascript libraries head.add( JavascriptImportWdg() ) # add the body body = my.body html.add( body ) # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript' # is not checked ... TODO: clean up and re-style to make look nicer body.add( """ <NOSCRIPT> <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;"> <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b> <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p> </div> </NOSCRIPT> """ % ( IconWdg.get_icon_path("ERROR") ) ) # add the content if my.widgets: content_wdg = my.get_widget('content') else: content_wdg = Widget() my.add(content_wdg) body.add( content_wdg ) body.add_event('onload', 'spt.onload_startup(this)') if web.is_admin_page(): from tactic_branding_wdg import TacticCopyrightNoticeWdg branding = TacticCopyrightNoticeWdg(show_license_info=True) body.add(branding) # add the admin bar security = Environment.get_security() if not web.is_admin_page() and security.check_access("builtin", "view_site_admin", "allow"): div = DivWdg() body.add(div) body.add_style("padding-top: 21px") div.add_class("spt_admin_bar") div.add_style("height: 15px") div.add_style("padding: 3px 0px 3px 15px") #div.add_style("margin-bottom: -5px") div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.7") div.add_style("width: 100%") #div.add_gradient("background", "background2", 20, 10) div.add_style("background-color", "#000") div.add_style("color", "#FFF") div.add_style("z-index", "1000") div.add_class("hand") div.set_box_shadow("0px 5px 5px") # remove icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Remove Admin Bar", icon=IconWdg.POPUP_WIN_CLOSE) icon_div.add(icon_button) icon_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var parent = bvr.src_el.getParent(".spt_admin_bar"); spt.behavior.destroy_element(parent); $(document.body).setStyle("padding-top", "0px"); ''' } ) div.add("<b>ADMIN >></b>") div.add_behavior( { 'type': 'listen', 'event_name': 'close_admin_bar', 'cbjs_action': ''' spt.behavior.destroy_element(bvr.src_el); $(document.body).setStyle("padding-top", "0px"); ''' } ) div.add_behavior( { 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.85) //new Fx.Tween(bvr.src_el).start('height', "30px"); ''' } ) div.add_behavior( { 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.7) //new Fx.Tween(bvr.src_el).start('height', "15px"); ''' } ) project_code = Project.get_project_code() div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var url = "/tactic/%s/link/_startup"; window.open(url); ''' % project_code } ) # Add the script editor listener load_div = DivWdg() body.add(load_div) load_div.add_behavior( { 'type': 'listen', 'event_name': 'show_script_editor', 'cbjs_action': ''' var js_popup_id = "TACTIC Script Editor"; var js_popup = $(js_popup_id); if( js_popup ) { spt.popup.toggle_display( js_popup_id, false ); } else { spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} ); } '''} ) # deal with the palette defined in /index which can override the palette if my.kwargs.get("hash") == (): key = "index" search = Search("config/url") search.add_filter("url", "/%s/%%"%key, "like") search.add_filter("url", "/%s"%key) search.add_where("or") url = search.get_sobject() if url: xml = url.get_xml_value("widget") palette_key = xml.get_value("element/@palette") # look up palette the expression for index from pyasm.web import Palette palette = Palette.get() palette.set_palette(palette_key) colors = palette.get_colors() colors = jsondumps(colors) script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_colors(%s); env.set_palette('%s'); ''' % (colors, palette_key) ) body.add(script) env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() login = Environment.get_login() user_name = login.get_value("login") user_id = login.get_id() login_groups = Environment.get_group_names() # add environment information script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_project('%s'); env.set_user('%s'); env.set_user_id('%s'); var login_groups = '%s'.split('|'); env.set_login_groups(login_groups); env.set_client_handoff_dir('%s'); env.set_client_repo_dir('%s'); ''' % (Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir,client_asset_dir)) body.add(script) # add a global container for commonly used widgets div = DivWdg() body.add(div) div.set_id("global_container") # add in the app busy widget # find out if there is an override for this search = Search("config/url") search.add_filter("url", "/app_busy") url = search.get_sobject() if url: busy_div = DivWdg() div.add(busy_div) busy_div.add_class( "SPT_PUW" ) busy_div.add_styles( "display: none; position: absolute; z-index: 1000" ) busy_div.add_class("app_busy_msg_block") busy_div.add_style("width: 300px") busy_div.add_style("height: 100px") busy_div.add_style("padding: 20px") busy_div.add_color("background", "background3") busy_div.add_border() busy_div.set_box_shadow() busy_div.set_round_corners(20) busy_div.set_attr("id","app_busy_msg_block") # put the custom url here title_wdg = DivWdg() busy_div.add(title_wdg) title_wdg.add_style("font-size: 20px") title_wdg.add_class("spt_app_busy_title") busy_div.add("<hr/>") msg_div = DivWdg() busy_div.add(msg_div) msg_div.add_class("spt_app_busy_msg") else: from page_header_wdg import AppBusyWdg div.add( AppBusyWdg() ) # popup parent popup = DivWdg() popup.set_id("popup") div.add(popup) # create another general popup popup_div = DivWdg() popup_div.set_id("popup_container") popup_div.add_class("spt_panel") popup = PopupWdg(id="popup_template",destroy_on_close=True) popup_div.add(popup) div.add(popup_div) # popup parent inner_html_div = DivWdg() inner_html_div.set_id("inner_html") div.add(inner_html_div) # add in a global color from tactic.ui.input import ColorWdg color = ColorWdg() div.add(color) # add in a global notify wdg from notify_wdg import NotifyWdg widget.add(NotifyWdg()) return widget
def handle_directories(self, top): # deal with asset directories top.add(DivWdg('Asset Folders', css='spt_info_title')) mailserver = Config.get_value("services", "mailserver") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("asset_base_dir: ") td.add_style("width: 150px") asset_base_dir = Config.get_value("checkin", "asset_base_dir") if asset_base_dir: table.add_cell(asset_base_dir) tr = table.add_row() tr.add_style('border-bottom: 1px #bbb solid') # check if it is writable is_writable = os.access(asset_base_dir, os.W_OK) span = SpanWdg("writable:") span.add_style('padding-left: 20px') td = table.add_cell(span) td = table.add_cell(str(is_writable)) else: table.add_cell("None configured") client_os = Environment.get_env_object().get_client_os() if os.name == 'nt': os_name = 'win32' else: os_name = 'linux' if client_os == 'nt': client_os_name = 'win32' else: client_os_name = 'linux' env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() table.add_row() td = table.add_cell("%s_server_handoff_dir: " % os_name) td.add_style("width: 150px") handoff_dir = Config.get_value("checkin", "%s_server_handoff_dir" % os_name) if handoff_dir: table.add_cell(handoff_dir) table.add_row() # check if it is writable is_writable = os.access(handoff_dir, os.W_OK) span = SpanWdg("writable:") span.add_style('padding-left: 20px') td = table.add_cell(span) td = table.add_cell(str(is_writable)) else: table.add_cell("None configured") table.add_row() td = table.add_cell("%s hand-off test: " % client_os_name) td.add_style("width: 150px") button = ActionButtonWdg(title='Test') button.add_behavior({ 'type': 'click_up', 'handoff_dir': client_handoff_dir, 'asset_dir': client_asset_dir, 'cbjs_action': ''' var env = spt.Environment.get(); var applet = spt.Applet.get(); var handoff_state = applet.exists(bvr.handoff_dir); var asset_state = applet.exists(bvr.asset_dir); if (asset_state == false) { env.set_transfer_mode("web"); spt.error('client repo directory is not accessible: ' + bvr.asset_dir); } else if (handoff_state == false) { env.set_transfer_mode("web"); spt.error('client handoff directory is not accessible: ' + bvr.handoff_dir); } else { env.set_transfer_mode("copy"); spt.info('<div>client handoff directory: ' + bvr.handoff_dir + '</div><br/><div>client repo directory :' + bvr.asset_dir + '</div><br/><div> can be successfully accessed.</div>', {type:'html'}); } ''' }) table.add_cell(button)
def handle_directories(self, top): # deal with asset directories top.add(DivWdg('Asset Folders', css='spt_info_title')) mailserver = Config.get_value("services", "mailserver") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("asset_base_dir: ") td.add_style("width: 150px") asset_base_dir = Config.get_value("checkin", "asset_base_dir") if asset_base_dir: table.add_cell( asset_base_dir ) tr = table.add_row() tr.add_style('border-bottom: 1px #bbb solid') # check if it is writable is_writable = os.access(asset_base_dir, os.W_OK) span = SpanWdg("writable:") span.add_style('padding-left: 20px') td = table.add_cell(span) td = table.add_cell(str(is_writable)) else: table.add_cell( "None configured") client_os = Environment.get_env_object().get_client_os() if os.name == 'nt': os_name = 'win32' else: os_name = 'linux' if client_os == 'nt': client_os_name = 'win32' else: client_os_name = 'linux' env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() table.add_row() td = table.add_cell("%s_server_handoff_dir: " % os_name) td.add_style("width: 150px") handoff_dir = Config.get_value("checkin", "%s_server_handoff_dir" % os_name) if handoff_dir: table.add_cell( handoff_dir ) table.add_row() # check if it is writable is_writable = os.access(handoff_dir, os.W_OK) span = SpanWdg("writable:") span.add_style('padding-left: 20px') td = table.add_cell(span) td = table.add_cell(str(is_writable)) else: table.add_cell( "None configured") table.add_row() td = table.add_cell("%s hand-off test: " % client_os_name) td.add_style("width: 150px") button = ActionButtonWdg(title='Test') button.add_behavior( { 'type': 'click_up', 'handoff_dir': client_handoff_dir, 'asset_dir': client_asset_dir, 'cbjs_action': ''' var env = spt.Environment.get(); var applet = spt.Applet.get(); var handoff_state = applet.exists(bvr.handoff_dir); var asset_state = applet.exists(bvr.asset_dir); if (asset_state == false) { env.set_transfer_mode("web"); spt.error('client repo directory is not accessible: ' + bvr.asset_dir); } else if (handoff_state == false) { env.set_transfer_mode("web"); spt.error('client handoff directory is not accessible: ' + bvr.handoff_dir); } else { env.set_transfer_mode("copy"); spt.info('<div>client handoff directory: ' + bvr.handoff_dir + '</div><br/><div>client repo directory :' + bvr.asset_dir + '</div><br/><div> can be successfully accessed.</div>', {type:'html'}); } ''' } ) table.add_cell( button )
def execute(my): input = my.get_input() search_type = input.get('search_type') if search_type != 'sthpw/transaction_log': print "ERROR: this trigger can only be executed for transaction_logs" return project = Project.get() # Things done in the Admin project are not sync'd. # NOTE: maybe need an option to enable this? if project.get_code() == 'admin': return log = input.get('sobject') transaction_code = log.get_value("code") # if this is a remote transaction, then do not create a job for it local_prefix = Config.get_value("install", "server") search = Search("sthpw/sync_server") search.add_filter("state", "online") servers = search.get_sobjects() #print "servers: ", len(servers) mode = input.get('mode') if not mode or mode == 'default': mode = 'xmlrpc' # This will transaction into a "file" folder mode = "file" file_mode = 'upload' # get some user info env = Environment.get() #user = env.get_user_name() #ticket = env.get_ticket() project_code = Project.get_project_code() from pyasm.security import AccessManager access_manager = AccessManager() for server in servers: # FIXME # check security #if not my.check_security(server): # print "Transaction denied due to security restrictions" # continue server_code = server.get_code() # don't publish a transaction back to the original server if log.get_value("server_code") == server_code: continue # check project security rules = server.get_value("access_rules"); if not rules: rules = "<rules/>" access_manager.add_xml_rules(rules) namespace = log.get_value("namespace") key1 = { 'code': namespace } key2 = { 'code': '*' } keys = [key1, key2] if not access_manager.check_access("project", keys, "allow", default="deny"): continue from tactic.ui.sync import SyncFilter sync_filter = SyncFilter(rules=rules, transaction=log) sync_filter.execute() filtered_xml = sync_filter.get_filtered_xml() message = sync_filter.get_message() # create a new job entry job = SearchType.create("sthpw/sync_job") job.set_value("state", "pending") job.set_value("server_code", server_code) job.set_value("transaction_code", transaction_code) job.set_user() host = server.get_value("host") job.set_value("command", "tactic.command.TransactionQueueCmd") kwargs = { 'server': server.get_value("code"), 'transaction_code': transaction_code, 'file_mode': file_mode, 'project_code': project_code, 'mode': mode } job.set_json_value("data", kwargs) job.commit()