forked from Soviet-Linux/OUR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkall
executable file
·46 lines (38 loc) · 1.44 KB
/
mkall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/env python3
# -*- coding: utf-8 -*-
# vim: set fileencoding=utf-8 :
# vim: set et ts=4 sw=4 sts=4 :
# vim: set ai :
#write a ECMP parser
import sqlite3
import os
import glob
if os.path.exists('all.db'):
os.remove('all.db')
def parse_ecmp(ecmp_file,ecmp_values):
with open(ecmp_file, 'r') as f:
for line in f:
line = line.strip()
if line.startswith('#'):
continue
if '=' not in line:
continue
key, value = line.split('=', 1)
key = key.strip()
value = value.strip()
if key in ecmp_values:
ecmp_values[key] = value
return ecmp_values
conn = sqlite3.connect('all.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS Packages (Name TEXT, Version TEXT, Type TEXT, Format TEXT,Section TEXT)''')
#get recursively all the .ecmp fils in the current directory without './'
ecmp_files = glob.glob('**/*.ecmp', recursive=True)
# get the first dir of the path
for ecmp_file in ecmp_files:
ecmp_values = {'name': '', 'version': '', 'type': '', 'format': 'ecmp', 'section': os.path.dirname(ecmp_file).split('/')[0]}
ecmp_values = parse_ecmp(ecmp_file,ecmp_values)
print(ecmp_values)
c.execute("INSERT INTO Packages VALUES (?,?,?,?,?)", (ecmp_values['name'],ecmp_values['version'],ecmp_values['type'],ecmp_values['format'],ecmp_values['section']))
conn.commit()
conn.close()