本文整理汇总了Python中dpa.ptask.area.PTaskArea.current方法的典型用法代码示例。如果您正苦于以下问题:Python PTaskArea.current方法的具体用法?Python PTaskArea.current怎么用?Python PTaskArea.current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dpa.ptask.area.PTaskArea
的用法示例。
在下文中一共展示了PTaskArea.current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def validate(self):
# current ptask/version
try:
area = PTaskArea.current()
self._current_ptask = PTask.get(area.spec)
self._current_ptask_version = self._current_ptask.latest_version
except PTaskError:
raise ActionError("Unable to find ptask: " + str(self._ptask))
# source ptask
if not isinstance(self._ptask, PTask):
try:
cur_spec = PTaskArea.current().spec
full_spec = PTaskSpec.get(self._ptask, relative_to=cur_spec)
self._ptask = PTask.get(full_spec)
except PTaskError:
raise ActionError("Unable to find ptask: " + str(self._ptask))
# source ptask version
if isinstance(self._version, PTaskVersion):
pass
elif self._version:
matches = PTaskVersion.list(
ptask=self._ptask.spec, number=self._version
)
if len(matches) != 1:
raise ActionError(
"Unable to find ptask '{p}' at version '{v}'".format(
p=self._ptask.spec, v=self._version
)
)
else:
self._version = matches[0]
else:
self._version = self._ptask.latest_version
# source subs
self._match_str = self._match_str.replace("%", ".*")
all_subs = self._version.subscriptions
self._subs_to_source = []
for sub in all_subs:
if re.search(self._match_str, sub.product_version_spec):
self._subs_to_source.append(sub)
if not self._subs_to_source:
raise ActionAborted("No subscriptions to source.")
示例2: _import_mari_plugins
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def _import_mari_plugins():
from dpa.ptask.area import PTaskArea
# first, get the context
ptask_area = PTaskArea.current()
# get a list of mari plugin directories
plugin_dirs = ptask_area.ancestor_paths(
'plugins/mari', include_install=False)
for plugin_dir in reversed(plugin_dirs):
if not os.path.isdir(plugin_dir):
continue
file_names = os.listdir(plugin_dir)
for file_name in file_names:
# only python files
if not file_name.endswith(".py"):
continue
full_path = os.path.join(plugin_dir, file_name)
module_name = 'mari_plugin_' + file_name.replace(".", "_")
try:
module = imp.load_source(module_name, full_path)
except Exception as e:
print "Unable to load mari plugin: " + full_path
traceback.print_exc()
示例3: get_import_files
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def get_import_files(cls, session, name, category, representation,
relative_to=None):
ptask_area = PTaskArea.current()
try:
import_dir = ptask_area.dir(dir_name='import', path=True)
except PTaskAreaError:
raise EntityError("Could not find import directory!")
import_dir = os.path.join(
import_dir, 'global', name, category, representation.type,
representation.resolution
)
# get the file in the import_dir
import_files = os.listdir(import_dir)
import_files = [f for f in import_files
if f.endswith('.' + representation.type)]
# prepend the import directory to get the full path
import_files = [os.path.join(import_dir, f) for f in import_files]
if relative_to:
import_files = [
os.path.relpath(f, relative_to) for f in import_files]
return import_files
示例4: setup_cl_args
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def setup_cl_args(cls, parser):
parser.add_argument(
"spec",
nargs="?",
default=PTaskArea.current().spec,
help="The production task specification."
)
parser.add_argument(
"-s", "--shell",
default=ShellFormatters.default().name,
choices=sorted([f.name for f in ShellFormatters.all()]),
help="Shell type env commands should target."
)
parser.add_argument(
"-p", "--previous",
nargs="?",
const="list",
help="Choose a previous ptask env."
)
parser.add_argument(
"-v", "--version",
type=int,
help="The version of the ptask to print info for."
)
示例5: queue_submit_cmd
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def queue_submit_cmd(command, queue_name, output_file=None, id_extra=None,
dt=None):
"""Create and submit a shell script with the given command."""
ptask_area = PTaskArea.current()
ptask_area.provision(QUEUE)
script_dir = ptask_area.dir(dir_name=QUEUE)
unique_id = get_unique_id(ptask_area.spec, id_extra=id_extra, dt=dt)
script_name = unique_id + '.sh'
log_name = unique_id + '.log'
script_path = os.path.join(script_dir, script_name)
log_path = os.path.join(script_dir, log_name)
with open(script_path, "w") as script_file:
script_file.write("#!/bin/bash\n")
script_file.write(command + "\n")
script_file.write("chmod 660 " + output_file + "\n")
os.chmod(script_path, 0770)
create_queue_task(queue_name, script_path, unique_id,
output_file=output_file, submit=True, log_path=log_path)
示例6: ptask_area
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def ptask_area(self):
"""Return the current ptask area for this session."""
if not hasattr(self, '_ptask_area'):
self._ptask_area = PTaskArea.current()
return self._ptask_area
示例7: execute
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def execute(self):
match_specs = self._complete(
self.spec,
relative_to=PTaskArea.current().spec,
)
if match_specs:
print " ".join([s for s in match_specs])
示例8: get_default_product_name
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def get_default_product_name():
name = "Comp"
ptask_area = PTaskArea.current()
if ptask_area:
name = PTaskSpec.name(ptask_area.spec) + name
return name
示例9: validate
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def validate(self):
if not isinstance(self._ptask, PTask):
try:
cur_spec = PTaskArea.current().spec
full_spec = PTaskSpec.get(self._ptask, relative_to=cur_spec)
self._ptask = PTask.get(full_spec)
except PTaskError:
raise ActionError("Could not determine ptask from: {p}".format(
p=self._ptask))
示例10: log_action
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def log_action(self):
if not self.__class__.logging:
return
# log the command
msg = "({s})".format(s=PTaskArea.current().spec)
msg += " " + " ".join(sys.argv)
self.logger.info(msg)
示例11: validate
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def validate(self):
if not self._message:
raise ActionError("Message can not be empty.")
try:
self._sender = User.current()
except UserError:
raise ActionError("Could not identify current user.")
# get ooto notification recipients from the configs
ptask_area = PTaskArea.current()
ooto_config = ptask_area.config(
OOTO_CONFIG_PATH,
composite_ancestors=True,
composite_method="append",
)
ooto_notify = ooto_config.get('notify', [])
self._to.extend(ooto_notify)
# for all usernames specified, make sure they're a valid user,
# get their email addresses.
recipients = set()
for recipient in self._to:
# assume already a valid email address
if "@" in recipient:
recipients.add(recipient)
else:
try:
recipient = User.get(recipient)
except UserError:
raise ActionError(
"Could not identify user: " + str(recipient)
)
else:
recipients.add(recipient.email)
if not recipients:
recipients = [self._sender.email]
self._to = recipients
# tag the message with a signature, including the current ptask area
# if there is one.
if ptask_area:
self._message += "\n\nCurrent ptask: {p}".format(p=ptask_area.spec)
self._message += "\n\n- {s}".format(s=self._sender.full_name)
self._subject = "OOTO: {fn} ({un})".format(
fn=self.sender.full_name,
un=self.sender.username,
)
示例12: __call__
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def __call__(self, parser, namespace, in_spec, option_string=None):
# assume the current ptask if not supplied
if not in_spec:
in_spec = "."
cur_spec = PTaskArea.current().spec
in_spec = in_spec.strip().strip(PTaskSpec.SEPARATOR)
full_spec = PTaskSpec.get(in_spec, relative_to=cur_spec)
setattr(namespace, self.dest, full_spec)
示例13: queue_submit_cmd
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def queue_submit_cmd(command, queue_name, output_file=None, id_extra=None):
"""Create and submit a shell script with the given command."""
ptask_area = PTaskArea.current()
ptask_area.provision(QUEUE)
script_dir = ptask_area.dir(dir_name=QUEUE)
now = datetime.datetime.now()
if not id_extra:
id_extra = now.strftime("%f")
unique_id = "{u}_{t}_{s}_{e}".format(
u=current_username(),
t=now.strftime("%Y_%m_%d_%H_%M_%S"),
s=ptask_area.spec.replace('=', '_'),
e=id_extra,
)
script_name = unique_id + '.sh'
log_name = unique_id + '.log'
script_path = os.path.join(script_dir, script_name)
log_path = os.path.join(script_dir, log_name)
with open(script_path, "w") as script_file:
script_file.write("#!/bin/bash\n")
script_file.write(command + "\n")
script_file.write("chmod 660 " + output_file + "\n")
os.chmod(script_path, 0770)
# ---- submit to the queue
from cheesyq import DPACheesyQ, DPADataLibrary, DPACheesyQTasks
data_lib = DPADataLibrary.DjangoLibrary(None)
render_task = DPACheesyQ.RenderTask()
render_task.taskid = unique_id
render_task.logFileName = log_path
render_task.outputFileName = output_file
data_lib.set(render_task.taskid, render_task)
render_task.addTask(script_path)
os.system("cqresubmittask {qn} {tid}".format(
qn=queue_name,
tid=render_task.taskid
))
print "Submitted task: " + str(render_task.taskid)
示例14: __init__
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def __init__(self):
ptask_area = PTaskArea.current()
options_config = ptask_area.config(OOTO_OPTIONS_CONFIG,
composite_ancestors=True)
icon_path = IconFactory().disk_path(OOTO_ICON_URI)
super(OotoDialog, self).__init__(
title='Out Of The Office (OOTO)',
options_config=options_config,
icon_path=icon_path,
action_button_text='Submit',
modal=False,
)
示例15: __init__
# 需要导入模块: from dpa.ptask.area import PTaskArea [as 别名]
# 或者: from dpa.ptask.area.PTaskArea import current [as 别名]
def __init__(self):
ptask_area = PTaskArea.current()
options_config = ptask_area.config(FAIL_OPTIONS_CONFIG,
composite_ancestors=True)
icon_path = IconFactory().disk_path(FAIL_ICON_URI)
super(FailDialog, self).__init__(
title='Failure Report',
options_config=options_config,
icon_path=icon_path,
action_button_text='Submit',
modal=False,
)