文档章节

RS code

anqiyouyou
 anqiyouyou
发布于 2017/06/26 14:34
字数 741
阅读 5
收藏 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")

© 著作权归作者所有

共有 人打赏支持
anqiyouyou
粉丝 0
博文 3
码字总数 1474
作品 0
QA/测试工程师
如何整理PHP分页代码,使其实现经典分页样式

请问一下,要如何让下面的代码可以让分页呈现出 首页 上一页 12345 下一页 尾页这种格式的,目前只是呈现出上一页 下一页

Binvor
2012/08/10
1K
1
基于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
Train Herblore Level with 9% off 500M runescape gold shop on RSorder 8.19-8.24

When an employer conducts a background rs3 gold check on their own they will usually only get a hold of information on the location held, dates associated with employment and in......

happiesgress
2016/08/22
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

JS:异步 - 面试惨案

为什么会写这篇文章,很明显不符合我的性格的东西,原因是前段时间参与了一个面试,对于很多程序员来说,面试时候多么的鸦雀无声,事后心里就有多么的千军万马。去掉最开始毕业干了一年的Jav...

xmqywx
今天
0
0
Win10 64位系统,PHP 扩展 curl插件

执行:1. 拷贝php安装目录下,libeay32.dll、ssleay32.dll 、 libssh2.dll 到 C:\windows\system32 目录。2. 拷贝php/ext目录下, php_curl.dll 到 C:\windows\system32 目录; 3. p...

放飞E梦想O
今天
0
0
谈谈神秘的ES6——(五)解构赋值【对象篇】

上一节课我们了解了有关数组的解构赋值相关内容,这节课,我们接着,来讲讲对象的解构赋值。 解构不仅可以用于数组,还可以用于对象。 let { foo, bar } = { foo: "aaa", bar: "bbb" };fo...

JandenMa
今天
1
0
OSChina 周一乱弹 —— 有人要给本汪介绍妹子啦

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @莱布妮子 :分享水木年华的单曲《中学时代》@小小编辑 手机党少年们想听歌,请使劲儿戳(这里) @须臾时光:夏天还在做最后的挣扎,但是晚上...

小小编辑
今天
18
4
centos7安装redis及开机启动

配置编译环境: sudo yum install gcc-c++ 下载源码: wget http://download.redis.io/releases/redis-3.2.8.tar.gz 解压源码: tar -zxvf redis-3.2.8.tar.gz 进入到解压目录: cd redis-3......

hotsmile
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部