def run(): print() for arg in sys.argv: if arg.lower() == '--recreate': gso('rmdir /s ' + testEnvLinux().py36) gso('dir /b') recreates = "[Recreate Virtual Environment]" else: recreates = "" if arg.lower() == '--no_virtualenv': newenv = False newenvs = "[No Virtual Environment]" else: newenv = True newenvs = "" if newenv: # Write pipeline here if you will use virtual environment. setup = ['dir', 'xcopy ..\src .\Archarios /O /X /E /H /K /Y', 'dir', 'cd Archarios', 'echo %cd%'] test = ['python archariosframework.py --web'] cleanup = ['cd ..', 'rmdir Archarios /s'] else: # Write pipeline here if you will NOT use virtual environment. setup = ['dir', 'cd src', 'echo %cd%'] test = ['python archariosframework.py --test'] cleanup = [] print("{0} Activated switches: {1} {2}".format(sys.argv[0], newenvs, recreates)) testEnvLinux(newenv).main(setup, test, cleanup)
def run(): print() for arg in sys.argv: if arg.lower() == '--recreate': gso('rm -rf ' + testEnvLinux().py36) gso('ls -a') recreates = "[Recreate Virtual Environment]" else: recreates = "" if arg.lower() == '--no_virtualenv': newenv = False newenvs = "[No Virtual Environment]" else: newenv = True newenvs = "" if newenv: # Write pipeline here if you will use virtual environment. setup = ['ls', 'cp -r ../src ./Archarios', 'ls', 'cd Archarios', 'pwd'] test = ['python3 archariosframework.py --test'] cleanup = ['cd ..', 'rm -rf Archarios/'] else: # Write pipeline here if you will NOT use virtual environment. setup = ['ls', 'cd src', 'pwd'] test = ['python3 archariosframework.py --test'] cleanup = [] print("{0} Activated switches: {1} {2}".format(sys.argv[0], newenvs, recreates)) testEnvLinux(newenv).main(setup, test, cleanup)
def heandle(self): try: add_port = "Cscript C:\Windows\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_%s -h %s -o raw" install_printer = "rundll32 printui.dll,PrintUIEntry /if /b 打印机%s /f \"%s\" /r IP_%s /m \"%s\" /z" inf_4471 = "\\\\192.168.3.93\\all\打印机\\4471彩机\%s\Software\PCL\\amd64\Simplified_Chinese\\001\FX6BEAL.inf" # inf_3060_10 = "\\\\192.168.3.93\\all\打印机\\3060黑白\win10 64\PCL\\amd64\\001\FX6MHAL.inf" inf_3060 = "\\\\192.168.3.93\\all\打印机\\3060黑白\%s\cswnd\PCL\\amd64\\001\FX6MHAL.inf" sys_info = self.Jud_sys_version() v = self.v.get() r = self.msg(1, "确定安装%s吗?,此操作会将之前安装的打印机覆盖。" % (PRINTER.get(v)[0])) # r = messagebox.askokcancel('消息框', "确定安装%s吗?"%(PRINTER.get(v)[0])) ip = PRINTER.get(v)[1] self.pc_data = self.Jud_sys_version() if r: retcode, output = gso(add_port % (ip, ip)) # print(add_port % (ip, ip)) self.text.insert(INSERT, "已创建/更新端口%s\n端口添加成功!!\n" % (ip)) self.text.insert(INSERT, "开始执行安装程序.....\n") if retcode == 0: if v == '1' or v == '2': inf_path = inf_4471 % (sys_info.get('version') + ' ' + sys_info.get('machine')) # time.sleep(2) retcode1, output1 = gso( install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) # print(install_printer%(ip,inf_path,ip,PRINTER.get(v)[2])) if retcode1 == 0: self.text.insert(INSERT, "安装程序开始执行,后台服务安装中,请稍后......\n") # time.sleep(5) self.text.insert(INSERT, "安装程序完成\n") self.text.insert(INSERT, "稍等几分钟后,请打开控制面板查看新的打印机") retcode2, output2 = gso("control") else: self.text.insert(INSERT, "安装程序出错,请联系管理员!!!!") if v == '3': inf_path = inf_3060 % (sys_info.get('version') + ' ' + sys_info.get('machine')) retcode1, output1 = gso( install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) if retcode1 == 0: self.text.insert(INSERT, "安装程序开始执行,后台服务安装中,请稍后......\n") self.text.insert(INSERT, "安装程序完成,\n") self.text.insert(INSERT, "稍等几分钟后,请打开控制面板查看新的打印机") retcode2, output2 = gso("control") else: self.text.insert(INSERT, "安装程序出错,请联系管理员!!!!") else: self.text.insert(INSERT, "\n端口%s添加失败,请联系管理员!!!!" % (ip)) except Exception: print(Exception)
def createEnvironment(self): if not os.path.exists(self.py36): print(self.CGR, "[i] Creating Environment...", self.END) gso('virtualenv --python=python3.6 ' + self.py36) else: print(self.CGR, "[i] Reusing Previous Environment...", self.END) print(self.CGR, "[i] Remove {} to recreate...".format(self.py36)) os.chdir(self.py36) self.rootdir = os.getcwd() print(self.CGR, "[i] Environment set! Now starting to test...", self.END) timeout(1)
def createEnvironment(self, create_new_environment=True): if self.newenv: if not os.path.exists(self.py36): print(self.CGR, "[i] Creating Environment...", self.END) os.mkdir(self.py36) else: print(self.CGR, "[i] Reusing Previous\ Environment...", self.END) print(self.CGR, "[i] Remove {} or run with \ `--recreate` switch to recreate virtual environment...".format(self.py36)) os.chdir(self.py36) else: print(self.CY, "[i] Not testing on a\ virtual environment!", self.END) if gso('git stash push')[0] == 0: pass else: print(self.CR, "[i] Cannot stash\ current changes! Please manually") print("stash or commit your current\ changes to continue.", self.END) sys.exit(6) self.rootdir = os.getcwd() print(self.CGR, "[i] Environment set!\ Now starting to test...", self.END) timeout(1)
def main(self, *args): self.createEnvironment() stages = [] for arg in args: stages.append(arg) iterate = 0 for stage in stages: iterate += 1 print(self.CGR, "[i] Running stage #" + str(iterate), self.END) for command in stage: if not self.justContinue: self.run(command) else: self.report.append((-1, 'Skipped by CI Emulator.')) self.justContinue = False continue rc = self.get_results() if not self.newenv: if gso('git stash pop')[0] == 0: sys.exit(rc) else: print(self.CR, "[i] Cannot pop previous stash! Please\ manually type 'git stash pop' to get back\ to work.", self.END) sys.exit(rc + 1) else: sys.exit(rc)
def _set_databases(self, db): get_db = gso([self.defs['engines'][self.pool['engine']]['get_db'].format(**self.pool)]) if get_db[0]: open(self._log_path, 'a').write(get_db[1] + '\n') print(t.red('Error trying to connect to {}, check logs on {}'.format(self.pool['engine'], self._log_path))) exit(1) else: self.db = db if type(db) == list else [i.split(' ')[0] for i in get_db[1].split('\n')]
def ping_loop(self): while True: if self.stopped: break ping_status_output = gso('ping -W 2 -c 1 ' + self.server) if ping_status_output[0] == 0: host_state = re.search('time=(\d+\.*\d+\s)ms', ping_status_output[1]) if host_state is not None: time.sleep(self.cycle_pause) self.status = '{} ms'.format(host_state.group(1)) elif ping_status_output[0] == 1: self.status = 'offline' elif ping_status_output[0] == 2: time.sleep(self.cycle_pause) if ping_status_output[1].find('unknown host'): self.status = 'unk host' elif ping_status_output[1].find('connect:'): self.status = 'no net'
def run(self, command): self.job_no += 1 if command.startswith('cd'): os.chdir(command.partition('cd ')[2]) else: self.result = gso(command) print(self.CG, "$ " + command, self.END) print(self.result[1]) print() if self.result[0] != 0: print( self.CR, "Job #{} failed! Exited with code #{}".format( str(self.job_no), str(self.result[0])), self.END) self.retcode = 1 else: self.retcode = 0 self.report.append(self.result) timeout(1) return self.retcode
from subprocess import getstatusoutput as gso import cgi print('content-type:text/plain') print() form_values = cgi.FieldStorage() content = form_values.getvalue("co") name_of_image = form_values.getvalue("na") image_version = form_values.getvalue("ver") username = form_values.getvalue("user") password = form_values.getvalue("pass") status = gso('sudo mkdir /dockerfiles') path = f'/dockerfiles/{name_of_image}' status = gso(f'sudo mkdir {path}') status = gso(f'sudo touch {path}/Dockerfile') status = gso(f'sudo chown apache {path}/Dockerfile') status = gso(f'sudo echo "{content}" >> {path}/Dockerfile') status = gso(f'sudo dos2unix {path}/Dockerfile') status = gso('sudo systemctl start docker') status = gso( f'sudo docker build -t {username}/{name_of_image}:{image_version} {path}') status = gso(f'sudo docker login -u {username} -p {password}') status = gso(f'sudo docker push {username}/{name_of_image}:{image_version}') print(status)
from subprocess import getstatusoutput as gso import cgi print('content-type:text/plain') print() form_values = cgi.FieldStorage() cmd = form_values.getvalue('dcmd').lower() osname = form_values.getvalue('osname') osimage = form_values.getvalue('img') if 'start docker' in cmd: s = gso('sudo systemctl start docker') print('Docker started sucessfully!' if s[0] == 0 else 'Failed to start docker!') elif 'stop docker' in cmd: s = gso('sudo systemctl stop docker') print('Docker stopped sucessfully' if s[0] == 0 else 'Failed to stop docker!') elif 'launch os' in cmd: s = gso(f'sudo docker run -d -i -t --name {osname} {osimage}') print('OS launched sucessfully!' if s[0] == 0 else 'Failed to launch!') elif 'docker state' in cmd:
# coding = utf-8 import platform, easygui, os from subprocess import getstatusoutput as gso from PIL import Image, ImageTk import tkinter as tk # 简单插入显示 # def show_jpg(): # root = tk.Tk() # im=Image.open("D:\printer\conf\ye.png") # img=ImageTk.PhotoImage(im) # imLabel=tk.Label(root,image=img).pack() # root.mainloop() # # if __name__ == '__main__': # show_jpg() path = os.getcwd() print(path) retcode2, output2 = gso("control")
#!/usr/bin/python3 from subprocess import getstatusoutput as gso import cgi print('content-type:text/plain') print() form_values = cgi.FieldStorage() no_of_datanodes = int(form_values.getvalue("nodn")) no_of_tasktracker = int(form_values.getvalue("nott")) status = gso("sudo chown apache /ansible-scripts/details.yml") #datanodes status = gso('sudo echo "datanodes:" >> /ansible-scripts/details.yml') for i in range(no_of_datanodes): status = gso(f'sudo echo " - dn{i}" >> /ansible-scripts/details.yml') #tasktrackers status = gso('sudo echo "tasktrackers:" >> /ansible-scripts/details.yml') for j in range(no_of_tasktracker): status = gso(f'sudo echo " - tt{j}" >> /ansible-scripts/details.yml') #running the playbooks #launch ec2-instances status = gso( "sudo /usr/local/bin/ansible-playbook /ansible-scripts/ec2-driver.yml") #configure the nodes
criterion=cri, random_state=int(rs)) classifier.fit(X_train, y_train) joblib.dump(classifier, '/ml_folder/model') # Predicting the Test set results y_pred = classifier.predict(X_test) # Making the Confusion Matrix from sklearn.metrics import confusion_matrix, accuracy_score cm = confusion_matrix(y_test, y_pred) print(f'''confusion matrix {cm}''') #pushing code to repo status = gso('mkdir /git-ws') status = gso('git init /git-ws') status = gso( f'cd /git-ws && git remote add origin https://github.com/{user_name}/{repo_name}.git' ) print(status[1]) status = gso('mv /ml_folder/model /git-ws') status = gso('mv /ml_folder/scalar /git-ws') status = gso('cd /git-ws && git add .') status = gso(f'cd /git-ws && git config user.name "{name}"') status = gso(f'cd /git-ws && git config user.email "{email}"') status = gso('cd /git-ws && git commit -m "committing model" .') status = gso('cd /git-ws && git branch -M main') status = gso('cd /git-ws && git push -u origin main') print(status[1])
#!/usr/bin/python3 from subprocess import getstatusoutput as gso import cgi print('content-type:text/plain') print() form_values = cgi.FieldStorage() remote_ip = form_values.getvalue('-ip-') passwd = form_values.getvalue('pw') status = gso('sudo touch /inven.txt') status = gso('sudo chown apache /inven.txt') status = gso('sudo /usr/bin/echo "[minikube_ip]" >> /inven.txt') status = gso( f'sudo /usr/bin/echo "{remote_ip} ansible_user=root ansible_ssh_pass={passwd} ansible_connection=ssh" >> /inven.txt' ) status = gso('sudo /usr/local/bin/ansible-playbook /ansible-scripts/mini.yml') print('successful' if status[0] == 0 else 'failed')
def heandle(self): sys_info = self.Jud_sys_version() system_version = sys_info.get('version') + ' ' + sys_info.get( 'machine') try: add_port = "Cscript C:\Windows\System32\Printing_Admin_Scripts\zh-CN\Prnport.vbs -a -r IP_%s -h %s -o raw" install_printer = "rundll32 printui.dll,PrintUIEntry /if /b 打印机%s /f \"%s\" /r IP_%s /m \"%s\" /z" v = self.v.get() r = self.msg(1, "确定安装%s吗?,此操作会将之前安装的打印机覆盖。" % (PRINTER.get(v)[0])) # r = messagebox.askokcancel('消息框', "确定安装%s吗?"%(PRINTER.get(v)[0])) ip = PRINTER.get(v)[1] self.pc_data = self.Jud_sys_version() if r: retcode, output = gso(add_port % (ip, ip)) print("添加端口命令:", add_port % (ip, ip)) if jud_samba(): inf_3060 = "\\\\192.168.3.93\\all\打印机\\3060黑白\%s\cswnd\PCL\\amd64\\001\FX6MHAL.inf" inf_c640e = "\\\\192.168.3.93\\all\打印机\\C364e彩机\%s\BHC554ePCL6Winx64_5400ZH-CN\KOAYTJ__.INF" else: inf_3060 = path + "\print\%s\PCL\\amd64\\001\FX6MHAL.inf" inf_c640e = path + "\print\%s\KOAYTJ__.INF" self.text.insert(INSERT, "已创建/更新端口%s\n端口添加成功!!\n" % (ip)) judge_info = judge() self.text.insert(INSERT, judge_info) downloaDriveInfo = downloaDrive(system_version, v) self.text.insert(INSERT, downloaDriveInfo) unzipFileInfo = unzipFile(path + "\print.zip", path + "\print") self.text.insert(INSERT, unzipFileInfo) self.text.insert(INSERT, "开始执行安装程序.....\n") if retcode == 0: # 安装科美打印机 if v == '1': inf_path = inf_c640e % system_version print("inf路径:", inf_path) print( "打印命令:", install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) retcode1, output1 = gso( install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) print(install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) if retcode1 == 0: self.text.insert(INSERT, "安装程序开始执行,后台服务安装中,请稍后......\n") self.text.insert(INSERT, "安装程序完成\n") self.text.insert(INSERT, "稍等几分钟后,请打开控制面板查看新的打印机") retcode2, output2 = gso("control") else: self.text.insert(INSERT, "安装程序出错,请联系管理员!!!!") # 安装富士乐施打印机 if v == '2' or v == '3': inf_path = inf_3060 % (sys_info.get('version') + ' ' + sys_info.get('machine')) print("inf路径:", inf_path) print( "打印命令:", install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) retcode1, output1 = gso( install_printer % (ip, inf_path, ip, PRINTER.get(v)[2])) if retcode1 == 0: self.text.insert(INSERT, "安装程序开始执行,后台服务安装中,请稍后......\n") self.text.insert(INSERT, "安装程序完成,\n") self.text.insert(INSERT, "稍等几分钟后,请打开控制面板查看新的打印机") retcode2, output2 = gso("control") else: self.text.insert(INSERT, "安装程序出错,请联系管理员!!!!") else: self.text.insert(INSERT, "\n端口%s添加失败,请联系管理员!!!!" % (ip)) except Exception: print(Exception)
def minikube_setup(): repo_name = '/etc/yum.repos.d/confi.repo' baseurl_path = 'baseurl=file:///run/media/root/RHEL-8-0-0-BaseOS-x86_64' status = gso('systemctl stop firewalld') status = gso('setenforce 0') #configuring yum repos status = gso(f'touch {repo_name}') status = gso(f'echo "[path1]" >> {repo_name}') status = gso( f'echo "baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/" >> {repo_name}' ) status = gso(f'echo "gpgcheck=0" >> {repo_name}') status = gso(f'echo "[path2]" >> {repo_name}') status = gso(f'echo "{baseurl_path}/AppStream" >> {repo_name}') status = gso(f'echo "gpgcheck=0" >> {repo_name}') status = gso(f'echo "[path3]" >> {repo_name}') status = gso(f'echo "{baseurl_path}/BaseOS" >> {repo_name}') status = gso(f'echo "gpgcheck=0" >> {repo_name}') time() print('yum repos configured!' if status[0] == 0 else 'failed to configure yum repos!') if status[0] != 0: exit() #installing docker community edition status = gso('yum install docker-ce --nobest -y') time() print('docker-ce installed successfully' if status[0] == 0 else 'failed to install docker-ce') if status[0] != 0: exit() status = gso('yum install conntrack-tools -y') ''' minikube installation minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. All you need is Docker. minimum requirements - 2 CPUs or more 2 2GB of free memory 20GB of free disk space Internet connection Docker ''' #x86 binary download status = gso( 'curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64' ) status = gso('sudo install minikube-linux-amd64 /usr/local/bin/minikube') time() print('minikube-linux-amd64 successfully installed' if status[0] == 0 else 'failed to install') if status[0] != 0: exit() ''' the none driver allows advanced minikube users to skip VM creation, allowing minikube to be run on a user-supplied VM ''' status = gso('minikube config set driver none') status = gso( 'minikube start --driver=none --kubernetes-version=v1.20.0 --memory=1800mb ' ) time() print('minikube started' if status[0] == 0 else 'failed to start minikube') if status[0] != 0: exit() ''' kubectl installation The Kubernetes command line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. ''' #downloading version v1.20.0 status = gso( 'curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.0/bin/linux/amd64/kubectl' ) #make the kubectl binary executable status = gso('chmod +x ./kubectl') #move the binary in to your PATH status = gso('sudo mv ./kubectl /usr/local/bin/kubectl') time() print('kubectl installed successfully' if status[0] == 0 else 'failed to install kubectl') print('enviornment ready' if status[0] == 0 else 'failed to build the enviornment')
#!/usr/bin/python3 # -*- coding: utf-8 -*- #Slow as all hell, reuse this crap instead of calling bah #Tests the grammar.... Oh boy! import io import sys from subprocess import getstatusoutput as gso import zirsam import zirsam.dendrography as dendrography import zirsam.config as config camxes_cmd = "echo %r | java -Xss64m -jar /home/poseidon/Development/ideas/camxes/lojban_peg_parser.jar -t" gso_fail = len(gso(camxes_cmd % (''))[1]) def compare_camxes(line): #Seems to work. res = gso(camxes_cmd % (line))[1] return res[gso_fail:] == line def compare_jbofihe(line): return gso("echo %r | jbofihe" % (line))[0] == 0 #def compare_zirsam(line): #r = gso("echo %r | ~/sync/Development/JBOPARSER/dendrography.py --all-error" % line)[0] #return r == 0 def compare_zirsam(line): s = dendrography.Stream(config.Configuration(stdin=io.StringIO(line), args=['--all-error', '--forbid-warn', '--no-exit'], stdout=io.StringIO(), stderr=io.StringIO()))
def compare_camxes(line): #Seems to work. res = gso(camxes_cmd % (line))[1] return res[gso_fail:] == line
def compare_jbofihe(line): return gso("echo %r | jbofihe" % (line))[0] == 0
#!/usr/bin/python3 from subprocess import getstatusoutput as gso import cgi print('content-type:text/plain') print() form_values = cgi.FieldStorage() names = [['vpc_name', 'vpcn'], ['vpc_cidr', 'vpcc'], ['subnet_name1', 'su1'], ['subnet_name2', 'su2'], ['subnet_cidr1', 'sc1'], ['subnet_cidr2', 'sc2'], ['instance_name1', 'ec1'], ['instance_name2', 'ec2']] x = gso('sudo chown apache /ansible-scripts/details.yml') for tag, n in names: line = f'"{tag}: {form_values.getvalue(n)}"' x = gso(f'sudo echo {line} >> /ansible-scripts/details.yml') x = gso('sudo /usr/local/bin/ansible-playbook /ansible-scripts/launch_vpc.yml') print(x)
#!/usr/bin/python3 from subprocess import getstatusoutput as gso import cgi print('content-type:text/plain') print() form_values = cgi.FieldStorage() names = [['kube_master_name', 'mn'], ['kube_worker_name1', 'w1n'], ['kube_worker_name2', 'w2n'], ['cidr_block', 'cdb']] x = gso('sudo chown apache /ansible-scripts/details.yml') for tag, n in names: line = f'"{tag}: {form_values.getvalue(n)}"' x = gso(f'sudo echo {line} >> /ansible-scripts/details.yml') x = gso( 'sudo /usr/local/bin/ansible-playbook /ansible-scripts/launching_instances.yml' ) x = gso( 'sudo /usr/local/bin/ansible-playbook /ansible-scripts/master_config.yml') x = gso( 'sudo /usr/local/bin/ansible-playbook /ansible-scripts/worker_config.yml') print(x)
#!/usr/bin/python3 from subprocess import getstatusoutput as gso print('content-type:text/plain') print() x = gso( 'sudo /usr/local/bin/ansible-playbook /ansible-scripts/elastic_cache.yml') print(x)