文档章节

RS code

anqiyouyou
 anqiyouyou
发布于 2017/06/26 14:34
字数 741
阅读 6
收藏 0

 

import os

import shutil

import xml.dom.minidom

import revitfarm.core.util.general as gr

 

from revitfarm.core.util.log import get_empty_logger

 

class RevitServerTools:

SERVER_ROOT_DIR = "C:/Temp/ServerRootDir"

DEBUG_MODES = "[DebugModes]"

REGRESSION_TEST_VALUE = "RegressionTestServerBasedWorkflow=1"

 

def __init__(self, versionID, rsOnIIS_exe_path, rs_release_path, rs_program, logger):

self.versionId = versionID

self.rsOnIIS_exe_path = rsOnIIS_exe_path

self.rs_release_path = rs_release_path

self.rs_program = rs_program

self.logger = logger

 

def set_env(self, versionId):

setEnv_cmd = '@reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v RSROLE' + versionId + ' /t reg_expand_sz /d "Accelerator,Admin,Host" /f'

return gr.run_simple_cmd(setEnv_cmd, input=None, success_code=0, logger=self.logger)

 

def rm_env(self, versionId):

rmEnv_cmd = '@reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v RSROLE' + versionId + ' /f'

return gr.run_simple_cmd(rmEnv_cmd, input=None, success_code=0, logger=self.logger)

 

def rsOnIIS_install(self, versionID, rsOnIIS_exe_path, rs_release_path):

"""

install RevitServer

"""

cmd_line = rsOnIIS_exe_path+" i=\""+rs_release_path+"\" r="+versionID+" e"

subst_result = self.run_subst()

cmd_line = self.analyze_virtual_disk(subst_result, cmd_line)

run_cmd_result = gr.run_simple_cmd(cmd_line, input=None, success_code=0, logger=self.logger)

return run_cmd_result

 

def rsOnIIS_uninstall(self, versionID, rsOnIIS_exe_path):

"""

uninstall RevitServer

"""

cmd_line = rsOnIIS_exe_path+" u"

subst_result = self.run_subst()

cmd_line = self.analyze_virtual_disk(subst_result, cmd_line)

run_cmd_result = gr.run_simple_cmd(cmd_line, input=None, success_code=0, logger=self.logger)

return run_cmd_result

 

def run_subst(self):

subst_result = gr.run_command("subst", success_code=0, logger=None, print_output=False, progress_bar_pattern=None)

return subst_result[1]

 

def analyze_virtual_disk(self, subst_result, cmd_line):

"""

replace virtual replace with real disk path

:return: real path

"""

if str(subst_result) != "[]":

self.logger.info("slave machine have virtual disk need make install disk replace")

subst_reuslt = str(subst_result).replace("[","").replace("]","").replace("'","").replace(">","").split(": =")

truth_disk = str(subst_reuslt[0]).replace("\\\\", "\\").replace(" ", "")

virtual_disk = str(subst_reuslt[1]).replace("\\\\", "\\").replace(" ", "")

cmd_line = cmd_line.replace(truth_disk, virtual_disk+"\\")

self.logger.info("replace cmd is ".format(cmd_line))

return cmd_line

 

@classmethod

def find_word(cls, filename, word):

with open(filename, 'r') as f:

for l in f.readlines():

if word in l:

return True

return False

 

@classmethod

def find_word_location(cls, filename, word):

with open(filename, "r") as f:

all_text = f.read()

index = all_text.find(word)

return index

 

@classmethod

def insert_text(cls, filename, index, word):

with open(filename, "r") as f:

all_text = f.read()

new_text = all_text[:index] + word + all_text[index:]

with open(filename, "w+") as file:

file.write(new_text)

return new_text

 

@classmethod

def remove_text(cls, filename, word):

with open(filename, "r") as f:

all_text = f.read()

new_text = all_text.replace("\n" + word, "")

with open(filename, "w+") as file:

file.write(new_text)

return new_text

 

@classmethod

def check_create_rsn(self, rsn_ini):

if not os.path.exists(rsn_ini):

with open(rsn_ini, "w+") as rsn:

rsn.write("localhost")

 

@classmethod

def check_create_debug(cls, debug_ini):

if not os.path.exists(debug_ini):

with open(debug_ini, "w+") as debug:

debug.write("{}\n{}".format(cls.DEBUG_MODES, cls.REGRESSION_TEST_VALUE))

else:

if not cls.find_word(debug_ini, cls.REGRESSION_TEST_VALUE):

if (cls.find_word(debug_ini, cls.DEBUG_MODES)):

index = cls.find_word_location(debug_ini, cls.DEBUG_MODES)

cls.insert_text(debug_ini, index+12, "\n")

cls.insert_text(debug_ini, index+13, cls.REGRESSION_TEST_VALUE)

else:

index = 0

cls.insert_text(debug_ini, index, "\n")

cls.insert_text(debug_ini, index, cls.REGRESSION_TEST_VALUE)

cls.insert_text(debug_ini, index, "\n")

cls.insert_text(debug_ini, index, cls.DEBUG_MODES)

 

@classmethod

def remove_debug(cls, debug_ini):

if os.path.exists(debug_ini):

if (cls.find_word(debug_ini, cls.REGRESSION_TEST_VALUE)):

cls.remove_text(debug_ini, cls.REGRESSION_TEST_VALUE)

 

 

def execute_RS(self, versionId, ServerRootDir, rsOnIIS_exe_path, rs_release_path, rs_program):

rsn_ini = os.path.join(rs_program, "RSN.ini")

 

#Step1:set env execute setEnv.bat ,and check if failed will stop

self.logger.info("set ENV RSROLE%s" %versionId)

cmd_result = self.set_env(versionId)

if(cmd_result[0] is not True):

self.logger.error("set Env Failed")

 

#Step 2 prepare temp dir and file

self.logger.info("mkdir temp/ServerRootDir")

try:

if not os.path.exists(ServerRootDir):

os.mkdir(ServerRootDir)

except FileExistsError as e:

self.logger.error(e)

 

# make rsn.ini in Program dir

self.logger.info("create rsn.ini ")

self.check_create_rsn(rsn_ini)

 

#Step 3 unstall and install rsOnIIS,and check if failed python will exit

self.logger.info("uninstall RevitServer ")

unrs_result = self.rsOnIIS_uninstall(versionId, rsOnIIS_exe_path)

if(unrs_result[0] is not True):

self.logger.error("unstall rsOnIIS failed")

 

self.logger.info("install RevitServer ")

inrs_result = self.rsOnIIS_install(versionId, rsOnIIS_exe_path,rs_release_path)

if(inrs_result[0] is not True):

self.logger.error("install rsOnIIS failed")

 

def clean_RS(self, versionId, ServerRootDir, rsOnIIS_exe_path, rs_program):

# uninstall_cmd = self.rsOnIIS_uninstall(versionId, rsOnIIS_exe_path)

# rmEnv_cmd = '@reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v RSROLE'+versionId+' /f'

rsn_ini = os.path.join(rs_program, "RSN.ini")

 

# clean rsn.ini

if os.path.exists(rsn_ini):

os.remove(rsn_ini)

 

#Step 2 Uninstall rsOnIIS.exe

self.logger.info("uninstall RevitServer ")

unrs_result = self.rsOnIIS_uninstall(versionId, rsOnIIS_exe_path)

if(unrs_result[0] is not True):

self.logger.info("unstall rsOnIIS failed")

#Step3:delete env execute and check if failed will stop

self.logger.info("rm env RSROLE%s" %versionId)

cmd_result=self.rm_env(versionId)

if(cmd_result[0] is not True):

self.logger.error("rm env failed")

 

@classmethod

def get_version_id(cls, web_config_path, logger=None):

try:

if logger is None:

logger = get_empty_logger()

dom = xml.dom.minidom.parse(web_config_path)

service_node = dom.getElementsByTagName("client")

service_model = service_node[0].childNodes[1].getAttribute("address")

start = service_model.rfind("ModelService")

version_id = service_model[int(start + 12):int(start + 16)]

except SyntaxError as error:

logger.error(error)

return version_id

 

@classmethod

def generate_rs_onIIS_exe_path(cls, local_job_package_root):

return os.path.join(local_job_package_root, "Regression", "_RegressionTools", "RSInstallUtils", "rsOnIIS.exe")

 

@classmethod

def generate_rs_path(cls, local_job_package_root):

return os.path.join(local_job_package_root, "RevitServer")

 

@classmethod

def generate_rs_release_path(cls, local_job_package_root):

return os.path.join(local_job_package_root, "RevitServer", "Enterprise", "Releasex64")

 

@classmethod

def generate_web_config_path(cls,local_job_package_root):

return os.path.join(local_job_package_root, "RevitServer", "Enterprise","Releasex64", "Services", "RS.Service.Protected.Model", "web.config")

© 著作权归作者所有

共有 人打赏支持
上一篇: 页面加载等待
下一篇: RS UnitTest
anqiyouyou
粉丝 0
博文 3
码字总数 1474
作品 0
QA/测试工程师
私信 提问
如何整理PHP分页代码,使其实现经典分页样式

请问一下,要如何让下面的代码可以让分页呈现出 首页 上一页 12345 下一页 尾页这种格式的,目前只是呈现出上一页 下一页 implemented Render_PageLinks(). Please note, this class is ent...

Binvor
2012/08/10
1K
1
g1 fullgc时间超长到时服务超时

如题,full gc导致服务停止响应,大神帮忙分析分析~ Java HotSpot(TM) 64-Bit Server VM (25.60-b23) for linux-amd64 JRE (1.8.0_60-b27), built on Aug 4 2015 12:19:40 by "java_re" wit......

Itdotaer
2017/07/09
156
2
基于NodeJs的微信第三方平台认证授权流程

需要解决的问题 微信的第三方开发者平台采用的是OAuth的认证流程。因此,需要解决的问题是: 按照OAuth的流程,调用微信第三方平台的api来获取preauthenticatioincode 等参数,提供授权页面让...

奔走在IT路上
2016/04/21
999
0
在Windows环境,用Java读写SQLite数据库文件(.db文件)

转自:http://www.cnblogs.com/anee/p/3483339.html import java.sql.*; import org.sqlite.JDBC; /** * Very Basic SQLite Database Example * @author Brandon Tanner */ public class dbR......

菜鸟的博客
2017/04/13
0
0
Up to 9% off rs2 gold for Ninja update 9.8-9.18,Ready to gain?

If you looking for massive amounts of storage, you in luck! The Corsair Obsidian buy cheap runescape gold 900D was built with you in mind. The 900D comes with three hard drive c......

happiesgress
2017/09/06
0
0

没有更多内容

加载失败,请刷新页面

加载更多

deepin中配置robot framework环境

本文永久更新地址:https://my.oschina.net/bysu/blog/2989005 【若要到岸,请摇船:开源中国 不最醉不龟归】 1.在终端中输入pip,回车,如果提示没有该命令,则先安转pip sudo apt-get inst...

不最醉不龟归
33分钟前
2
0
OSChina 周日乱弹 —— 钱不还,我就当你人不在了

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @莱布妮子 :分享Bigleaf的单曲《小鹿》 《小鹿》- Bigleaf 手机党少年们想听歌,请使劲儿戳(这里) 周日在家做什么? 做手工呀, @poorfis...

小小编辑
今天
114
4
EOS docker开发环境

使用eos docker镜像是部署本地EOS开发环境的最轻松愉快的方法。使用官方提供的eos docker镜像,你可以快速建立一个eos开发环境,可以迅速启动开发节点和钱包服务器、创建账户、编写智能合约....

汇智网教程
今天
20
0
《唐史原来超有趣》的读后感优秀范文3700字

《唐史原来超有趣》的读后感优秀范文3700字: 作者:花若离。我今天分享的内容《唐史原来超有趣》这本书的读后感,我将这本书看了一遍之后就束之高阁了,不过里面的内容一直在在脑海中回放,...

原创小博客
今天
30
0
IC-CAD Methodology知识图谱

CAD (Computer Aided Design),计算机辅助设计,指利用计算机及其图形设备帮助设计人员进行设计工作,这个定义同样可以用来近似描述IC公司CAD工程师这个岗位的工作。 早期IC公司的CAD岗位最初...

李艳青1987
今天
39
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部