Compare commits
3 Commits
bf30531bb8
...
a0475b87a9
| Author | SHA1 | Date | |
|---|---|---|---|
| a0475b87a9 | |||
| 446c080d2a | |||
| eab802a5b9 |
62
create_yml/main.py
Normal file
62
create_yml/main.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
|
def read_and_modify_one_block_of_yaml_data(filename = str,key = str,value = str):
|
||||||
|
with open(filename, 'r') as f:
|
||||||
|
data = yaml.safe_load(f)
|
||||||
|
data[f'{key}'] = f'{value}'
|
||||||
|
with open(filename, 'w') as file:
|
||||||
|
yaml.dump(data,file,sort_keys=False)
|
||||||
|
print('done!')
|
||||||
|
|
||||||
|
|
||||||
|
def read_modify_save_yaml_data(filename,index,key,value,write_file):
|
||||||
|
with open(filename,'r') as f:
|
||||||
|
data = yaml.safe_load_all(f)
|
||||||
|
loaded_data = list(data)
|
||||||
|
print(loaded_data)
|
||||||
|
loaded_data[index][f'{key}'].append(f'{value}')
|
||||||
|
with open(filename, 'w') as file:
|
||||||
|
yaml.dump_all(loaded_data,file, sort_keys=False)
|
||||||
|
print(loaded_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
#read yaml
|
||||||
|
with open('/home/jonnybravo/Projekte/docker-compose/adguard-home/docker-compose.yml', 'r') as file:
|
||||||
|
prime_service = yaml.safe_load(file)
|
||||||
|
#print(prime_service)
|
||||||
|
print(prime_service["services"]["adguardhome"]["image"])
|
||||||
|
#write yaml
|
||||||
|
my_yaml = yaml.safe_load('''
|
||||||
|
---
|
||||||
|
age: 30
|
||||||
|
automobiles:
|
||||||
|
- brand: Honda
|
||||||
|
type: Odyssey
|
||||||
|
year: 2018
|
||||||
|
- brand: Toyota
|
||||||
|
type: Sienna
|
||||||
|
year: 2015
|
||||||
|
name: John
|
||||||
|
test:
|
||||||
|
- test1
|
||||||
|
- test2
|
||||||
|
''')
|
||||||
|
#parsing yaml
|
||||||
|
yaml = ruamel.yaml.YAML()
|
||||||
|
yaml.indent(sequence=4, offset=2)
|
||||||
|
#yaml.dump(foo, sys.stdout)
|
||||||
|
|
||||||
|
#print(pars_test)
|
||||||
|
#writing test_yaml
|
||||||
|
with open('test.yml', 'w') as file:
|
||||||
|
yaml.dump(my_yaml, file)
|
||||||
|
|
||||||
|
#example modify yaml
|
||||||
|
#read_and_modify_one_block_of_yaml_data(filename="test.yml", key="year", value="2020")
|
||||||
|
#read_modify_save_yaml_data('test.yml', 0, 'test', 'test3', "test2")
|
||||||
12
create_yml/test.yml
Normal file
12
create_yml/test.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
age: 30
|
||||||
|
automobiles:
|
||||||
|
- brand: Honda
|
||||||
|
type: Odyssey
|
||||||
|
year: 2018
|
||||||
|
- brand: Toyota
|
||||||
|
type: Sienna
|
||||||
|
year: 2015
|
||||||
|
name: John
|
||||||
|
test:
|
||||||
|
- test1
|
||||||
|
- test2
|
||||||
43
jenkins/example_xml.xml
Normal file
43
jenkins/example_xml.xml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?xml version='1.1' encoding='UTF-8'?>
|
||||||
|
<project>
|
||||||
|
<description></description>
|
||||||
|
<keepDependencies>false</keepDependencies>
|
||||||
|
<properties/>
|
||||||
|
<scm class="hudson.plugins.git.GitSCM" plugin="git@5.0.0">
|
||||||
|
<configVersion>2</configVersion>
|
||||||
|
<userRemoteConfigs>
|
||||||
|
<hudson.plugins.git.UserRemoteConfig>
|
||||||
|
<url>{git_url}</url>
|
||||||
|
<credentialsId>4ee2c832-863c-41c3-8f9b-0962c7b8439f</credentialsId>
|
||||||
|
</hudson.plugins.git.UserRemoteConfig>
|
||||||
|
</userRemoteConfigs>
|
||||||
|
<branches>
|
||||||
|
<hudson.plugins.git.BranchSpec>
|
||||||
|
<name>*/master</name>
|
||||||
|
</hudson.plugins.git.BranchSpec>
|
||||||
|
</branches>
|
||||||
|
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
|
||||||
|
<submoduleCfg class="empty-list"/>
|
||||||
|
<extensions/>
|
||||||
|
</scm>
|
||||||
|
<canRoam>true</canRoam>
|
||||||
|
<disabled>false</disabled>
|
||||||
|
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||||
|
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||||
|
<triggers>
|
||||||
|
<hudson.triggers.SCMTrigger>
|
||||||
|
<spec>H/2 * * * *</spec>
|
||||||
|
<ignorePostCommitHooks>false</ignorePostCommitHooks>
|
||||||
|
</hudson.triggers.SCMTrigger>
|
||||||
|
</triggers>
|
||||||
|
<concurrentBuild>false</concurrentBuild>
|
||||||
|
<builders>
|
||||||
|
<hudson.tasks.Shell>
|
||||||
|
<command>{command}</command>
|
||||||
|
<configuredLocalRules/>
|
||||||
|
</hudson.tasks.Shell>
|
||||||
|
</builders>
|
||||||
|
<publishers/>
|
||||||
|
<buildWrappers/>
|
||||||
|
</project>
|
||||||
|
|
||||||
28
jenkins/modify_all_jenkins_conf.py
Normal file
28
jenkins/modify_all_jenkins_conf.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
def read_sshkeys(target_folder = str, search_string = str):
|
||||||
|
key_liste = []
|
||||||
|
for root, dirs, files in os.walk(target_folder, topdown=False, ):
|
||||||
|
for name in files:
|
||||||
|
if name == search_string:
|
||||||
|
FullPATH = str(os.path.join(root, name))
|
||||||
|
#if FullPATH.endswith(".pub") is False :#and FullPATH.endswith("known_hosts") is False and FullPATH.endswith("authorized_keys") is False:
|
||||||
|
#if FullPATH.
|
||||||
|
key_liste.append({"FullPath": FullPATH,
|
||||||
|
"Name": name,
|
||||||
|
"Root": root,
|
||||||
|
"Folder": dirs})
|
||||||
|
return key_liste
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
search_jenkins_folder = "/home/jonnybravo/.jenkins/data/jobs"
|
||||||
|
for i in read_sshkeys(target_folder=search_jenkins_folder, search_string="config.xml"):
|
||||||
|
print(i["FullPath"])
|
||||||
|
with open(i["FullPath"], 'r') as file:
|
||||||
|
data = file.read()
|
||||||
|
data = data.replace('<daysToKeep>-1</daysToKeep>', '')
|
||||||
|
with open(i["FullPath"], 'w') as file:
|
||||||
|
file.write(data)
|
||||||
27
jenkins/read_version.py
Normal file
27
jenkins/read_version.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import jenkins, os
|
||||||
|
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
#connect
|
||||||
|
server = jenkins.Jenkins('https://man-dan-03:9443', username='JonnyBravo', password='116a45abc20fff8ae5ac67cdac1d65c687')
|
||||||
|
user = server.get_whoami()
|
||||||
|
version = server.get_version()
|
||||||
|
#vars_für den Job
|
||||||
|
job_name="test_4"
|
||||||
|
finish_config=job_name + "_config.xml"
|
||||||
|
git_url='https://gitea.schlaubistechtalk.de/JonnyBravo/test_play.git'
|
||||||
|
command_line='./test_play.yml'
|
||||||
|
|
||||||
|
print('Hello %s from Jenkins %s' % (user['fullName'], version))
|
||||||
|
|
||||||
|
with open("example_xml.xml", "rt") as fin:
|
||||||
|
with open(finish_config, "wt") as fout:
|
||||||
|
for line in fin:
|
||||||
|
fout.write(line.format(git_url=git_url,command=command_line ))
|
||||||
|
|
||||||
|
|
||||||
|
tree = ET.parse(finish_config)
|
||||||
|
root = tree.getroot()
|
||||||
|
xml_str = ET.tostring(root, encoding='utf8', method='xml').decode()
|
||||||
|
|
||||||
|
server.create_job(name=job_name,config_xml=xml_str)
|
||||||
3
start_vms/main.py
Normal file
3
start_vms/main.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
vboxmanage startvm ansible_umgebung_ubuntu_1682357579668_76595 --type headless
|
||||||
39
xml_test/main.py
Normal file
39
xml_test/main.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
XMLexample_stored_in_a_string ='''<?xml version ="1.0"?>
|
||||||
|
<COUNTRIES>
|
||||||
|
<country name ="INDIA">
|
||||||
|
<neighbor name ="Dubai" direction ="W"/>
|
||||||
|
</country>
|
||||||
|
<country name ="Singapore">
|
||||||
|
<neighbor name ="Malaysia" direction ="N"/>
|
||||||
|
</country>
|
||||||
|
</COUNTRIES>
|
||||||
|
'''
|
||||||
|
mytree = ET.parse('xmldocument.xml.txt')
|
||||||
|
myroot = mytree.getroot()
|
||||||
|
|
||||||
|
# iterating through the price values.
|
||||||
|
for prices in myroot.iter('price'):
|
||||||
|
# updates the price value
|
||||||
|
prices.text = str(float(prices.text)+10)
|
||||||
|
# creates a new attribute
|
||||||
|
prices.set('newprices', 'yes')
|
||||||
|
|
||||||
|
# creating a new tag under the parent.
|
||||||
|
# myroot[0] here is the first food tag.
|
||||||
|
ET.SubElement(myroot[0], 'tasty')
|
||||||
|
for temp in myroot.iter('tasty'):
|
||||||
|
# giving the value as Yes.
|
||||||
|
temp.text = str('YES')
|
||||||
|
|
||||||
|
# deleting attributes in the xml.
|
||||||
|
# by using pop as attrib returns dictionary.
|
||||||
|
# removes the itemid attribute in the name tag of
|
||||||
|
# the second food tag.
|
||||||
|
myroot[1][0].attrib.pop('itemid')
|
||||||
|
|
||||||
|
# Removing the tag completely we use remove function.
|
||||||
|
# completely removes the third food tag.
|
||||||
|
myroot.remove(myroot[2])
|
||||||
|
|
||||||
|
mytree.write('output.xml')
|
||||||
11
xml_test/xmldocument.xml
Normal file
11
xml_test/xmldocument.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--COUNTRIES is the root element-->
|
||||||
|
<COUNTRIES>
|
||||||
|
<country name="INDIA">
|
||||||
|
<neighbor name="Dubai" direction="W"/>
|
||||||
|
</country>
|
||||||
|
<country name="Singapore">
|
||||||
|
<neighbor name="Malaysia" direction="N"/>
|
||||||
|
</country>
|
||||||
|
</COUNTRIES>
|
||||||
|
|
||||||
Reference in New Issue
Block a user