本文整理汇总了Python中tactic_client_lib.TacticServerStub.upload_directory方法的典型用法代码示例。如果您正苦于以下问题:Python TacticServerStub.upload_directory方法的具体用法?Python TacticServerStub.upload_directory怎么用?Python TacticServerStub.upload_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tactic_client_lib.TacticServerStub
的用法示例。
在下文中一共展示了TacticServerStub.upload_directory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from tactic_client_lib import TacticServerStub [as 别名]
# 或者: from tactic_client_lib.TacticServerStub import upload_directory [as 别名]
#.........这里部分代码省略.........
job.commit()
return
import zlib, binascii
#transaction_data = Common.process_unicode_string(transaction_xml)
transaction_data = transaction_xml.to_string()
if isinstance(transaction_data, unicode):
transaction_data = transaction_data.encode('utf-8')
length_before = len(transaction_data)
compressed = zlib.compress(transaction_data)
ztransaction_data = binascii.hexlify(compressed)
ztransaction_data = "zlib:%s" % ztransaction_data
length_after = len(ztransaction_data)
print("transaction log recompress: ", "%s%%" % int(float(length_after)/float(length_before)*100), "[%s] to [%s]" % (length_before, length_after))
# reset the transaction log sobject with the new xml. This
# should be harmless because it is never commited
log.set_value("transaction", ztransaction_data)
# NOTE: not really a command. Just a set of actions
cmd = TransactionFilesCmd(transaction_xml=transaction_xml)
paths = cmd.execute()
from pyasm.search import TableDataDumper
# drop the transaction into a folder
if sync_mode == 'file':
base_dir = server.get_value("base_dir", no_exception=True)
if not base_dir:
base_dir = Config.get_value("checkin", "win32_dropbox_dir")
if not base_dir:
raise Exception("Must define a base_dir for sync_mode=file")
ticket = server.get_value("ticket")
self.handle_file_mode(base_dir, transaction_code, paths, log, transaction_xml, ticket)
return
# xmlrpc mode
from tactic_client_lib import TacticServerStub
remote_server = TacticServerStub(
protocol='xmlrpc',
site=site,
server=host,
project=project_code,
user=user,
password=password,
ticket=ticket
)
# if the mode is undo, then execute an undo
if sync_mode == 'undo':
remote_server.undo(transaction_id=log.get_code(), is_sync=True)
else:
# upload all of the files
try:
if file_mode == 'upload':
for path in paths:
if os.path.isdir(path):
print("upload dir: ", path)
remote_server.upload_directory(path)
else:
print("upload file: ", path)
remote_server.upload_file(path)
#print("ping: ", remote_server.ping())
remote_server.execute_transaction(log.get_data(), file_mode=file_mode)
except Exception as e:
print("Error sending remote command [%s]" % str(e))
job = self.kwargs.get("job")
job.set_value("error_log", str(e))
#job.set_value("state", "error")
job.commit()
# print the stacktrace
import traceback
tb = sys.exc_info()[2]
stacktrace = traceback.format_tb(tb)
stacktrace_str = "".join(stacktrace)
print("-"*50)
print(stacktrace_str)
print("Error: ", str(e))
print("-"*50)
raise
job = self.kwargs.get("job")
job.set_value("error_log", "")
job.commit()
示例2: execute
# 需要导入模块: from tactic_client_lib import TacticServerStub [as 别名]
# 或者: from tactic_client_lib.TacticServerStub import upload_directory [as 别名]
#.........这里部分代码省略.........
search = Search("sthpw/transaction_log")
search.add_filter("code", transaction_code)
log = search.get_sobject()
if not log:
print "WARNING: No transaction_log [%s] exists" % transaction_code
return
# provide an opportunity to filter out the transaction log
# If a server is a complete copy, then no filter is necessary
message, transaction_xml = my.filter_transaction( log, server )
if not transaction_xml.get_nodes("transaction/*"):
print "No actions in transaction passed security ... skipping sync to [%s]" % server.get_code()
job = my.kwargs.get("job")
job.set_value("error_log", message)
job.commit()
return
# reset the transaction log sobject with the new xml. This
# should be harmless because it is never commited
log.set_value("transaction", transaction_xml.to_string())
# NOTE: not really a command. Just a set of actions
cmd = TransactionFilesCmd(transaction_xml=transaction_xml)
paths = cmd.execute()
from pyasm.search import TableDataDumper
# drop the transaction into a folder
if mode == 'file':
base_dir = server.get_value("base_dir", no_exception=True)
if not base_dir:
base_dir = Config.get_value("checkin", "win32_dropbox_dir")
if not base_dir:
raise Exception("Must define a base_dir for sync_mode=file")
ticket = server.get_value("ticket")
my.handle_file_mode(base_dir, transaction_code, paths, log, transaction_xml, ticket)
return
# xmlrpc mode
from tactic_client_lib import TacticServerStub
remote_server = TacticServerStub(
protocol='xmlrpc',
server=host,
project=project_code,
user=user,
password=password,
ticket=ticket
)
# if the mode is undo, then execute an undo
if mode == 'undo':
print "mode = undo"
remote_server.undo(transaction_id=log.get_code(), is_sync=True)
else:
# upload all of the files
try:
if file_mode == 'upload':
for path in paths:
if os.path.isdir(path):
print "upload dir: ", path
remote_server.upload_directory(path)
else:
print "upload file: ", path
remote_server.upload_file(path)
#print "ping: ", remote_server.ping()
remote_server.execute_transaction(log.get_data(), file_mode=file_mode)
except Exception, e:
print "Error sending remote command [%s]" % str(e)
job = my.kwargs.get("job")
job.set_value("error_log", str(e))
#job.set_value("state", "error")
job.commit()
# print the stacktrace
import traceback
tb = sys.exc_info()[2]
stacktrace = traceback.format_tb(tb)
stacktrace_str = "".join(stacktrace)
print "-"*50
print stacktrace_str
print "Error: ", str(e)
print "-"*50
raise