commit message from python script
This commit is contained in:
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
|
||||
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)
|
||||
@@ -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