test pkg.json

master
serkus01 2 years ago
parent 527275b112
commit 1b14970386

@ -9,7 +9,7 @@
"make.conf":"/etc/portage/make.conf/custom",
"package.use":"/etc/portage/package.use/custom",
"package.accept_keywords":"/etc/portage/package.accept_keywords/custom",
"package.mask":"/etc/portage/package.mask",
"package.mask":"/etc/portage/package.mask/custom",
"package.unmask":"/etc/portage/package.unmask/custom"
}

File diff suppressed because one or more lines are too long

@ -3,13 +3,105 @@
import os, sys
import json
from io import StringIO
from utils.utils import get_list_overlays, sort_install_pkg
from utils.utils import get_list_overlays, sort_install_pkg, load_config
from utils.GenRecovers import ScanRecoverFile
from utils.getUses import get_global_USE, get_local_USE
from utils.package import search
from utils.parsePortage import PortageConfig
# создаём раcширенную базу пакетов с приблизительной структурой
# pkg_list ={"category": [{name: name_pkg, versions:[list_version]}]}
# и кладём это всё в json
class PortageConfig():
def __init__(self):
self.Config = load_config()
self.TargetParse =['USE', 'USE_EXPAN', 'VIDEO_CARDS', 'ACCEPT_CHOSTS', 'ACCEPT_LICENSE','CCACHE_DIR', 'CCACHE_SIZE',
'EMERGE_DEFAULT_OPTS', 'CFLAGS', 'CXXFLAGS', 'MAKEOPTS']
self.MakeConfig={}
self.EnvPortaga ={}
#super().__init__(self.run())
def getLines(self, filename):
if os.path.exists(filename):
with open (filename, 'r') as f:
lines = f.read().split("\n")
else:
print("path is not Found")
return lines
def parseMakeConf(self):
StateBox = 'Null'
Lines = self.getLines(self.Config['Portage']['make.conf'])
for line in Lines:
if not line.startswith('#') and len(line.split("="))>1:
line.replace('"', "")
if StateBox == 'Null' and not line.endswith('"'):
StateBox = line.split('=')[0]
self.MakeConfig[StateBox] =[]
self.MakeConfig[StateBox] = line.split('=')[1].split(" ")
for i in line.split('=')[1].split(" "):
self.MakeConfig[split('=')[0]].append(i)
elif StateBox !='Null' and not line.endswith('"'):
StateBox = line.split('=')[1]
for i in line.split('=')[1].split(" "):
self.MakeConfig[line.split('=')[0]].append(i)
elif StateBox == 'Null' and line.endswith('"'):
#line.replace('"', "")
self.MakeConfig[line.split('=')[0]] = line.split('="')[1].split(" ")
self.EnvPortaga['make.conf'] = self.MakeConfig
print(self.MakeConfig)
def templParse(self, parm, res=False):
self.MakeConfig[parm] =[]
Lines = self.getLines(self.Config['Portage'][parm])
for i in Lines:
self.MakeConfig[parm].append(dict(Name=i.split(" ")[0], Uses=i.split(" ")[1:]))
if res:
print(self.MakeConfig[parm])
return self.MakeConfig[parm]
self.EnvPortaga[pam] = self.MakeConfig[parm]
def parsePackageUse(self):
self.templParse('package.use')
def parsePackageMasks(self):
sel.templParse('package.mask')
def parsePakageUnmask(self):
self.templParse("package.unmask")
def parsePackageKeywords(self):
self.templParse('package.accept_keywords')
def run(self):
self.parseMakeConf()
self.templParse('package.use', res=True)
self.templParse('package.mask', res=True)
self.templParse('package.unmask', res=True)
self.templParse('package.accept_keywords', res=True)
if __name__ == '__main__':
Test = PortageConfig()
if sys.argv[1] == "envMake":
Test.parseMakeConf()
elif sys.argv[1] == "use":
Test.templParse('package.use', res=True)
elif sys.argv[1] == "mask":
Test.templParse('package.mask', res=True)
elif sys.argv[1] == "unmask":
Test.templParse('package.unmask', res=True)
else:
pass
#
AliaseCategory ={
@ -62,7 +154,8 @@ def create_db():
pkg_list = {}
listUses = dict(LocalUSE = get_local_USE(), GlobalUSE = get_global_USE()) #[0] LocalUSE = get_local_USE(),
InstallPkgs = sort_install_pkg()
portage_list = {}
#portage_list = {}
#PortEnv = PortageConfig().run()
port_dir = ["/var/db/repos", "/usr/portage"]
if not os.path.exists('./pkgs.json'):
print("Create ramdb")
@ -108,8 +201,7 @@ def create_db():
#print([d.split('/')[-1]])
#"all_pkgs": all_pkgs, [0]
fn.write(json.dumps({ "all_pkgs": all_pkgs, "Catalog": pkg_list,"overlays": overlays, "aliases": AliaseCategory, "recovers": recovers, "usesDecription":listUses, "InstallPkgs":InstallPkgs }))
#json.length "InstallPkgs":InstallPkgs
fn.write(json.dumps({ "all_pkgs": all_pkgs, "Catalog": pkg_list,"overlays": overlays, "aliases": AliaseCategory, "recovers": recovers, "usesDecription":listUses, "InstallPkgs":InstallPkgs, 'EnvPortage': PortageConfig().run()}))
print(len(pkg_list))
"""
with open('./portage.json', 'w') as p:

@ -20,7 +20,7 @@ def search(r_p):
Description = ""
Home_page = ""
repository = ""
PortEnv = PortageConfig.run()
#PortEnv = PortageConfig.run()
try:
parametrs = ["HOMEPAGE", "IUSE","DESCRIPTION", "repository", "LICENSE"]
#print(r_p)

@ -1,15 +1,20 @@
#-*- codding:UTF-8 -*-
#!/usr/bin/env python
import os, sys, json
from utils.utils import *
try:
from utils.utils import load_config
except Exception as e:
print(e)
class PortageConfig():
def __init__(self):
self.Config = utls.load_config()
self.Config = load_config()
self.TargetParse =['USE', 'USE_EXPAN', 'VIDEO_CARDS', 'ACCEPT_CHOSTS', 'ACCEPT_LICENSE','CCACHE_DIR', 'CCACHE_SIZE',
'EMERGE_DEFAULT_OPTS', 'CFLAGS', 'CXXFLAGS', 'MAKEOPTS']
self.MakeConfig={}
self.EnvPortaga ={}
super().__init__(self.run())
def getLines(self, filename):
if os.path.exists(filename):
with open (filename, 'r') as f:
@ -39,7 +44,7 @@ class PortageConfig():
elif StateBox == 'Null' and line.endswith('"'):
#line.replace('"', "")
self.MakeConfig[line.split('=')[0]] = line.split('="')[1].split(" ")
self.EnvPortaga['make.conf'] = self.MakeConfig
self.EnvPortaga['make.conf'] = self.MakeConfig
print(self.MakeConfig)
def templParse(self, parm, res=False):
@ -52,7 +57,7 @@ class PortageConfig():
print(self.MakeConfig[parm])
return self.MakeConfig[parm]
self.EnvPortaga[pam] = self.MakeConfig[parm]
self.EnvPortaga[pam] = self.MakeConfig[parm]
def parsePackageUse(self):
self.templParse('package.use')
@ -66,12 +71,12 @@ class PortageConfig():
def parsePackageKeywords(self):
self.templParse('package.accept_keywords')
def run(self):
def run(self):
self.parseMakeConf()
templParse('package.use', res=True)
templParse('package.mask', res=True)
templParse('package.unmask', res=True)
templParse('package.accept_keywords', res=True)
self.templParse('package.use', res=True)
self.templParse('package.mask', res=True)
self.templParse('package.unmask', res=True)
self.templParse('package.accept_keywords', res=True)
if __name__ == '__main__':

@ -168,15 +168,16 @@ def sort_install_pkg():
INSTALL[d.replace(path,"").split('/')[0]].append(dict(name = pkg_name[:-1], ver = f.replace(pkg_name, "")))
else:
INSTALL[d.replace(path,"").split('/')[0]].append(dict(name = pkg_name[:-1],ver = f.replace(pkg_name, "")))
if d.replace(path, "").split('/')[0] not in INSTALL:
INSTALL[d.replace(path, "").split('/')[0]] = []
INSTALL[d.replace(path, "").split('/')[0]].append(f.replace(".ebuild", "") )
INSTALL[d.replace(path,"").split('/')[0]].append(f.replace(".ebuild", "")) #dict(name = pkg_name[:-1],ver = f.replace(pkg_name, "")
#if d.replace(path, "").split('/')[0] not in INSTALL:
INSTALL[d.replace(path, "").split('/')[0]] = []
INSTALL[d.replace(path, "").split('/')[0]].append(f.replace(".ebuild", "") )
INSTALL[d.replace(path,"").split('/')[0]].append(f.replace(".ebuild", "")) #dict(name = pkg_name[:-1],ver = f.replace(pkg_name, "")
#print(str(len(INSTALL)))
#return json.dumps({'install_pkgs':INSTALL})
return INSTALL
def ScanTreePortage():
DirsRoot = [ "/var/db/repos", "/usr/portage"]
ListTree = []

Loading…
Cancel
Save