I am using the following code to search through a folder structure and write all package names and versions into a string.
#!/usr/bin/python3
import glob
import json
repo_list = ["core", "multilib", "nonfree", "testing"]
for i in repo_list:
print(i)
for name in glob.glob('../' + i +'/*/spkgbuild'):
package_name = ''
package_version = ''
temp_json = ''
package = open(name,'r')
Lines = package.readlines()
for line in Lines:
if(line.strip().startswith('name')):
package_name = line.strip()[5:]
if(line.strip().startswith('version')):
package_version = line.strip()[8:]
if(package_name != '' and package_version != ''):
temp_json = {package_name: {"version": package_version}}
From this I actually want to have the following JSON object later:
{
"core": {
"package_name": {
"version": "1.1.1"
},
"package_name2": {
"version": "1.1.1"
}
}
}
I'm stuck writing the object now, can you help me there?
temp_json = {package_name: {"version": package_version}}totemp_json={}; temp_json[package_name] = {"version": package_version}