本文整理汇总了Python中pyasm.common.Environment.get方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.get方法的具体用法?Python Environment.get怎么用?Python Environment.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Environment
的用法示例。
在下文中一共展示了Environment.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_display
# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get [as 别名]
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
示例2: execute
# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get [as 别名]
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()
#.........这里部分代码省略.........
示例3: get_display
# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get [as 别名]
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()
#.........这里部分代码省略.........
示例4: handle_directories
# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get [as 别名]
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 )
示例5: execute
# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get [as 别名]
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 = {
#.........这里部分代码省略.........