文档章节

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
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
在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
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

没有更多内容

加载失败,请刷新页面

加载更多

Dubbo分析之Transport层

前言 上一篇文章Dubbo分析之Serialize层,介绍了最底层的序列化/反序列化层,本文继续分析Serialize层的上一层transport网络传输层,此层使用了现有的一些通讯开源框架(ex:netty,mina,grizzl...

ksfzhaohui
6分钟前
0
0
通告!Android 9 Pie未适配应用公示

8月7日,谷歌正式发布Android 9 Pie,至今已两月有余。近日,华为终端开放实验室对国内主流应用在Android 9 Pie的兼容性进行测试,结果显示:目前TOP3000应用兼容率已经超过95%,但仍有少量应...

安卓绿色联盟
9分钟前
0
0
Linux下多网卡绑定模式详解

在我们日常Linux使用中,一般对于生产网都会使用双网卡或多网卡接入,这样既能添加网络带宽,同时又能做相应的冗余,可谓好处多多。而一般我们都会使用Linux操作系统下自带的网卡绑定模式。这...

openthings
10分钟前
0
0
SylixOS中AARCH64跳转表实现原理

1. 跳转表存在的意义 1.1 内核模块反汇编 如下的程序清单,为一个内核模块的源码。 #define __SYLIXOS_KERNEL#include <SylixOS.h>#include <module.h> /* * SylixOS call module_i......

zhywxyy
11分钟前
0
0
聊一聊 Spring 中的线程安全性

本文摘自ImportNew公众号,摘录做学习资料,向大家推荐该公众号 Spring与线程安全 Spring作为一个IOC/DI容器,帮助我们管理了许许多多的“bean”。但其实,Spring并没有保证这些对象的线程安...

木子SMZ
12分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部