本文整理汇总了Python中pyasm.common.Common类的典型用法代码示例。如果您正苦于以下问题:Python Common类的具体用法?Python Common怎么用?Python Common使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Common类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check
def _check(self):
# This will kill the TACTIC process
# This is very harsh and should be used sparingly if at all
use_restart = Config.get_value("services", "use_periodic_restart")
if use_restart in [True, 'true']:
if self.num_checks and self.num_checks % self.kill_interval == 0:
# read pid file
log_dir = "%s/log" % Environment.get_tmp_dir()
file = open("%s/pid.%s" % (log_dir,self.port), "r")
pid = file.read()
file.close()
Common.kill(pid)
#self.run()
self.num_checks += 1
return
self.num_checks += 1
start = time.clock()
try:
response = self.check()
except IOError, e:
pid = self._get_pid()
if pid:
Common.kill(pid)
示例2: verify
def verify(my, login_name, password):
# replace cn=attribute with cn={login} in the config ldap_path
# e.g. cn={login},o=organization,ou=server,dc=domain
path = Config.get_value("security", "ldap_path")
server = Config.get_value("security", "ldap_server")
assert path, server
my.login_name = login_name
my.internal = True
path = path.replace("{login}", login_name)
#import ldap
try:
l = ldap.open(server)
l.simple_bind_s(path, password)
l.unbind()
return True
except:
login = Login.get_by_login(login_name)
# check if it's an external account and verify with standard approach
if login and login.get_value('location', no_exception=True) == 'external':
auth_class = "pyasm.security.TacticAuthenticate"
authenticate = Common.create_from_class_path(auth_class)
is_authenticated = authenticate.verify(login_name, password)
if is_authenticated == True:
my.internal = False
return True
elif login:
auth_class = "pyasm.security.TacticAuthenticate"
authenticate = Common.create_from_class_path(auth_class)
is_authenticated = authenticate.verify(login_name, password)
if is_authenticated == True:
my.internal = False
return True
raise SecurityException("Login/Password combination incorrect")
示例3: final_kill
def final_kill(self):
'''Kill the startup, startup_queue, watch_folder processes. This is used primarily in Windows Service.
Linux service should have actively killed the processes already'''
log_dir = "%s/log" % Environment.get_tmp_dir()
files = os.listdir(log_dir)
ports = []
watch_folders = []
queues = []
for filename in files:
base, ext = os.path.splitext(filename)
if base == 'pid':
ports.append(ext[1:])
elif base == 'watch_folder':
watch_folders.append(ext[1:])
elif base == 'startup_queue':
queues.append(ext[1:])
for port in ports:
try:
file_name = "%s/pid.%s" % (log_dir,port)
file = open(file_name, "r")
pid = file.readline().strip()
file.close()
Common.kill(pid)
except IOError, e:
continue
示例4: execute
def execute(my):
import atexit
import time
atexit.register( my.cleanup )
while 1:
my.check_existing_jobs()
my.check_new_job()
time.sleep(my.check_interval)
#DbContainer.close_thread_sql()
if my.max_jobs_completed != -1 and my.jobs_completed > my.max_jobs_completed:
Common.restart()
示例5: _process_pdf
def _process_pdf(my, file_name):
base, ext = os.path.splitext(file_name)
# naming convetion should take care of inserting a suffix like icon, web
# but these paths need a unique name
icon_file_name = base + "_icon.png"
tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name)
thumb_web_size = my.get_web_file_size()
web_file_name = base + "_web.png"
tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name)
if sys.platform == 'darwin':
return
else:
if not Common.which(convert_exe):
return
try:
my.file_path = my.file_path.encode('utf-8')
import shlex, subprocess
subprocess.call([convert_exe, '-geometry','80','-raise','2x2','%s[0]'%my.file_path,\
"%s"%tmp_icon_path])
subprocess.call([convert_exe, '-geometry','%sx%s'%(thumb_web_size[0], \
thumb_web_size[1]),'-raise','2x2','%s[0]' %my.file_path, "%s"%tmp_web_path])
except Exception, e:
print "Error extracting from pdf [%s]" % e
return
示例6: get_section_wdg
def get_section_wdg(self, view, editable=True, default=False):
title = ""
target_id = "sobject_relation"
if editable:
edit_mode = 'edit'
else:
edit_mode = 'read'
kwargs = {
'title': title,
'config_search_type': self.search_type,
'view': view,
'target_id': target_id,
'width': '300',
'prefix': 'manage_side_bar',
'mode': edit_mode,
'default': str(default)
}
if view in ["definition", "custom_definition"]:
kwargs['recurse'] = "false"
section_wdg = ViewSectionWdg(**kwargs)
class_path = Common.get_full_class_name(section_wdg)
section_div = DivWdg()
section_div.add_style("display: block")
section_div.set_attr('spt_class_name', class_path)
for name, value in kwargs.items():
if name == "config":
continue
section_div.set_attr("spt_%s" % name, value)
section_div.add(section_wdg)
return section_div
示例7: copy_sobject
def copy_sobject(my, sobject, dst_search_type, context=None, checkin_mode='inplace'):
new_sobject = SearchType.create(dst_search_type)
search_type = SearchType.get(dst_search_type)
columns = SearchType.get_columns(dst_search_type)
data = sobject.get_data()
for name, value in data.items():
if name in ['id','pipeline_code']:
continue
if name not in columns:
continue
if not value:
continue
if name == "code":
value = Common.get_next_sobject_code(sobject, 'code')
if not value:
continue
new_sobject.set_value(name, value)
if SearchType.column_exists(dst_search_type, "project_code"):
project_code = Project.get_project_code()
new_sobject.set_value("project_code", project_code)
new_sobject.commit()
# get all of the current snapshots and file paths associated
if not context:
snapshots = Snapshot.get_all_current_by_sobject(sobject)
else:
snapshots = [Snapshot.get_current_by_sobject(sobject, context)]
if not snapshots:
return
msgs = []
for snapshot in snapshots:
#file_paths = snapshot.get_all_lib_paths()
file_paths_dict = snapshot.get_all_paths_dict()
file_types = file_paths_dict.keys()
if not file_types:
continue
# make sure the paths match the file_types
file_paths = [file_paths_dict.get(x)[0] for x in file_types]
mode = checkin_mode
# checkin the files (inplace)
try:
context = snapshot.get_value('context')
checkin = FileCheckin(new_sobject, context=context, file_paths=file_paths, file_types=file_types, mode=mode)
checkin.execute()
#print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
except CheckinException, e:
msgs.append('Post-process Check-in Error for %s: %s ' %(context, e.__str__()))
示例8: color
def color(my, category, modifier=0, default=None):
if not category:
category = 'background'
# make default adjustments
if category.startswith("#"):
color = category
category = "color"
else:
color = my.colors.get(category)
if not color:
color = my.colors.get(default)
if not color:
color = category
if category == 'background2' and not color:
category = 'background'
modifier += 10
color = my.colors.get(category)
if category == 'color2' and not color:
category = 'color'
modifier += 10
color = my.colors.get(category)
return Common.modify_color(color, modifier)
示例9: get_related_wdg
def get_related_wdg(my, aliases):
div = DivWdg()
div.add("<b>Related links</b>:  ")
div.add_style("margin-top: 5px")
div.add_style("margin-bottom: 5px")
div.add_style("margin-left: 10px")
titles = [Common.get_display_title(x.replace("-"," ")) for x in aliases]
for alias, title in zip(aliases, titles):
link_div = SpanWdg()
div.add(link_div)
link_div.add_color("background", "background")
link_div.add(title)
link_div.add_behavior( {
'type': 'click_up',
'cbjs_action': '''
spt.help.set_top();
spt.help.load_alias("%s");
''' % alias
} )
link_div.add_class("spt_link")
link_div.add_class("hand")
return div
示例10: _process_video
def _process_video(my, file_name):
ffmpeg = Common.which("ffmpeg")
if not ffmpeg:
return
thumb_web_size = my.get_web_file_size()
thumb_icon_size = (120, 100)
exts = File.get_extensions(file_name)
base, ext = os.path.splitext(file_name)
icon_file_name = "%s_icon.png" % base
web_file_name = "%s_web.jpg" % base
tmp_icon_path = "%s/%s" % (my.tmp_dir, icon_file_name)
tmp_web_path = "%s/%s" % (my.tmp_dir, web_file_name)
#cmd = '''"%s" -i "%s" -r 1 -ss 00:00:01 -t 00:00:01 -s %sx%s -f image2 "%s"''' % (ffmpeg, my.file_path, thumb_web_size[0], thumb_web_size[1], tmp_web_path)
#os.system(cmd)
import subprocess
try:
subprocess.call([ffmpeg, '-i', my.file_path, "-y", "-ss", "00:00:01","-t","00:00:01",\
"-s","%sx%s"%(thumb_web_size[0], thumb_web_size[1]), "-f","image2", tmp_web_path])
my.web_path = tmp_web_path
except:
pass
try:
subprocess.call([ffmpeg, '-i', my.file_path, "-y", "-ss", "00:00:01","-t","00:00:01",\
"-s","%sx%s"%(thumb_icon_size[0], thumb_icon_size[1]), "-f","image2", tmp_icon_path])
my.icon_path = tmp_icon_path
except:
pass
示例11: get_display
def get_display(my):
top = my.top
class_name = my.kwargs.get("display_class_name")
kwargs = my.kwargs.get("display_kwargs")
top.add_style("border: solid 1px #777")
top.add_style("position: absolute")
top.add_style("z-index: 100")
top.add_style("box-shadow: 2px 2px 4px 4px #aaa")
top.add_style("background: #FFF")
top.add_style("margin-right: 200px")
top.add_style("margin-top: -20px")
top.add_style("overflow: hidden")
#widget_html = "<div style='border: solid 1px #777; position: absolute; z-index: 100; box-shadow: 2px 2px 4px 4px #aaa; background: #FFF; margin-right: 20px; margin-top: -20px; overflow: hidden'>" + widget_html + "</div>";
widget = Common.create_from_class_path(class_name, kwargs)
top.add(widget)
show_pointer = my.kwargs.get("show_pointer")
if show_pointer not in [False, 'false']:
my.get_arrow_wdg()
return top
示例12: _test_symlink
def _test_symlink(my):
if os.name == 'nt':
return
# create a new test.txt file
file_path = "./symlink.txt"
file = open(file_path, 'w')
file.write("symlink test")
file.close()
checkin = FileCheckin(my.person, file_path, context="sym_test", checkin_type='auto')
checkin.execute()
snap = Snapshot.get_versionless(my.person.get_search_type(), my.person.get_id(), "sym_test", mode='latest', create=False)
my.assertEquals(True, isinstance(snap, Snapshot))
if snap:
lib_path =snap.get_lib_path_by_type('main')
my.assertEquals(True, os.path.exists(lib_path))
rel_path = os.readlink(lib_path)
lib_dir = os.path.dirname(lib_path)
# this is essentially handle_link() in FileUndo class
wd = os.getcwd()
os.chdir(lib_dir)
real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
# lib_path points to real_path
expected_rel_path = Common.relative_path(lib_path, real_path)
my.assertEquals(True, os.path.exists(real_path))
my.assertEquals(expected_rel_path, rel_path)
os.chdir(wd)
示例13: filter_line_handler
def filter_line_handler(my, path, line):
'''NOT used now'''
return line
# this is only called if the project code is different from the
# template code
file_name = os.path.basename(path)
if file_name in ['sthpw_project.spt']:
# change codes to project code
if line.startswith('''insert.set_value('code','''):
line = '''insert.set_value('code', """%s""")\n''' % my.project_code
elif line.startswith('''insert.set_value('title','''):
title = Common.get_display_title(my.project_code)
line = '''insert.set_value('title', """%s""")\n''' % title
elif line.startswith('''insert.set_value('is_template','''):
if my.is_template:
line = '''insert.set_value('is_template', """true""")\n'''
else:
line = '''insert.set_value('is_template', """false""")\n'''
elif file_name in ['sthpw_schema.spt']:
if line.startswith('''insert.set_value('code','''):
line = '''insert.set_value('code', """%s""")\n''' % my.project_code
elif file_name in ['sthpw_pipeline.spt']:
if line.startswith('''insert.set_value('project_code','''):
line = '''insert.set_value('project_code', """%s""")\n''' % my.project_code
return line
示例14: execute
def execute(my):
import cherrypy
print
print "Stopping TACTIC ..."
print
print " ... stopping Schduler"
scheduler = Scheduler.get()
scheduler.stop()
print " ... stopping Cherrypy"
cherrypy.engine.stop()
cherrypy.engine.exit()
print " ... closing DB connections"
DbContainer.close_all_global_connections()
print " ... kill current process"
Common.kill()
print "Done."
示例15: get_display
def get_display(my):
sobject = my.get_current_sobject()
mode = my.get_option("mode")
if not mode:
mode = "sandbox"
widget = Widget()
sobject_dir = ""
sobject_lib_dir = ""
# find the path to open explorer
if sobject.is_insert():
button = IconWdg("No Path Found", IconWdg.CROSS, long=False)
else:
try:
if mode == "sandbox":
sobject_dir = my.get_base_dir(sobject)
elif mode in ["client_repo", "repository"]:
sobject_dir = my.get_client_repo_dir(sobject)
sobject_lib_dir = my.get_lib_dir(sobject)
sobject_dir = sobject_dir.strip()
sobject_dir = Common.process_unicode_string(sobject_dir)
except TacticException, e:
print "WARNING: ", str(e)
button = IconWdg("No Path Found", IconWdg.CROSS, long=False)
else: