Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
max-line-length = 120
exclude =
config/supported_distros.py,
distro_data/,
react-frontend/,
.claude/,
__pycache__,
*.pyc
per-file-ignores =
bin/config_build.py:E501
126 changes: 66 additions & 60 deletions bin/config_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,84 @@
RHEL_reg = r'(x?RHEL)_(\d{1,2})_(\d{1,2}).*\.json'
Ubuntu_reg = r'(x?Ubuntu)_(\d{1,2})_(\d{1,2}).*\.json'
regexes = [
re.compile(SLES_reg),
re.compile(RHEL_reg),
re.compile(Ubuntu_reg)
re.compile(SLES_reg),
re.compile(RHEL_reg),
re.compile(Ubuntu_reg)
]


def scan():
return os.listdir(DATA_FILE_LOCATION)
return os.listdir(DATA_FILE_LOCATION)


def packagetype(file):
global SLES_reg, RHEL_reg, Ubuntu_reg, regexes
for ind,reg in enumerate(regexes):
if reg.match(file):
addfile(file, ind)
for ind, reg in enumerate(regexes):
if reg.match(file):
addfile(file, ind)


def addfile(file, ind):
global SLES_reg, RHEL_reg, Ubuntu_reg, regexes
flag = False
with open(SUPPORTED_DISTRO_FILE) as DATA:
data = DATA.read()
groups = regexes[ind].search(file)
name = re.sub(r'^x', '', groups.group(1).replace('_', ' '))
if not ind == 0:
if name in data and not file in data:
print(f"Found new file: {file}")
start = data.index(name) + len(name)+7
new_data = f"\t'{groups.group(1)} {groups.group(2)}.{groups.group(3)}': '{file}',\n"
flag = True
else:
if name in data and not file in data:
print(f"Found new file: {file}")
start = data.index(name) + len(name)+7
new_data = f"\t'SLES {groups.group(4)} {'' if groups.group(6)==None else groups.group(6)}': '{file}',\n"
flag = True

if flag:
with open(SUPPORTED_DISTRO_FILE, 'r+') as DATA:
DATA.seek(start)
next_data = DATA.read()
DATA.seek(start)
DATA.write(new_data)
DATA.write(next_data)
flag = False
with open(SUPPORTED_DISTRO_FILE) as DATA:
data = DATA.read()
groups = regexes[ind].search(file)
name = re.sub(r'^x', '', groups.group(1).replace('_', ' '))
if ind != 0:
if name in data and file not in data:
print(f"Found new file: {file}")
start = data.index(name) + len(name) + 7
new_data = f"\t'{groups.group(1)} {groups.group(2)}.{groups.group(3)}': '{file}',\n"
flag = True
else:
if name in data and file not in data:
print(f"Found new file: {file}")
start = data.index(name) + len(name) + 7
new_data = (
f"\t'SLES {groups.group(4)} "
f"{'': if groups.group(6) is None else groups.group(6)}': '{file}',\n"
)
flag = True

def format_data():
duplicate = []
if flag:
with open(SUPPORTED_DISTRO_FILE, 'r+') as DATA:
old_format = DATA.read()
DATA.truncate(0)
new_format = re.sub(r"(json',\n})", "json'\n}", old_format)
DATA.seek(0)
DATA.write(new_format)
DATA.seek(start)
next_data = DATA.read()
DATA.seek(start)
DATA.write(new_data)
DATA.write(next_data)


def format_data():
with open(SUPPORTED_DISTRO_FILE, 'r+') as DATA:
old_format = DATA.read()
DATA.truncate(0)
new_format = re.sub(r"(json',\n})", "json'\n}", old_format)
DATA.seek(0)
DATA.write(new_format)


def del_cache():
try:
print("Attempting to delete cached_data.json...")
os.remove(f'{DATA_FILE_LOCATION}/cached_data.json')
except:
print("File not found in directory.")
try:
print("Attempting to delete cached_data.json...")
os.remove(f'{DATA_FILE_LOCATION}/cached_data.json')
except OSError:
print("File not found in directory.")


def pull_new(files):
global regexes
print("Attempting to update PDS data sources...")
for file in files:
if any(regex.match(file) for regex in regexes):
print(f'Updating {file}...')
subprocess.run([f'{SDT_BASE}/bin/package_build.py', file], stdout=subprocess.DEVNULL)
print("Attempting to update PDS data sources...")
for file in files:
if any(regex.match(file) for regex in regexes):
print(f'Updating {file}...')
subprocess.run([f'{SDT_BASE}/bin/package_build.py', file], stdout=subprocess.DEVNULL)


if __name__ == "__main__":
print("Scanning distro_data directory...")
files = scan()
for file in files:
packagetype(file)
format_data()
pull_new(files)
del_cache()
print('Done.')
print("Scanning distro_data directory...")
files = scan()
for file in files:
packagetype(file)
format_data()
pull_new(files)
del_cache()
print('Done.')
Loading