Some changes

master
Sergey Kalinin 2017-12-04 13:19:04 +03:00
parent 9904d5b4e9
commit 4efc72e071
3 changed files with 24 additions and 213 deletions

35
dm.py
View File

@ -30,6 +30,7 @@ def firstInit():
# Если конфиг уже есть читаем его если нет, создаем и потом читаем
if os.path.isfile(cfg_file):
print('Read config -' + cfg_file)
config.read(cfg_file)
else:
# Запись конфигурации в файл 'example.cfg'
@ -42,13 +43,14 @@ def firstInit():
template_dir = config.get('Directory', 'template_dir')
db_type = config.get('DataBase', 'db_type')
db_hostname = config.get('DataBase', 'db_hostname')
db_name = config.get('DataBase', 'db_name')
template_file = os.path.join(template_dir, "{}.json".format(db_name))
if db_type == 'sqlite':
db_name = os.path.join(work_dir, config.get('DataBase', 'db_name'))
else:
db_name = config.get('DataBase', 'db_name')
db_name = "{}.{}".format(os.path.join(work_dir, db_name), 'sqlite')
db_user = config.get('DataBase', 'db_user')
db_password = config.get('DataBase', 'db_password')
# Создаём нужные каталоги
if os.path.isdir(work_dir):
print(work_dir + " already exists")
@ -59,15 +61,17 @@ def firstInit():
else:
os.mkdir(template_dir)
# копируем и читаем файл шаблон БД
template_file = os.path.join(template_dir, 'tables.json')
#print("template file "+ template_file)
#template_file = os.path.join(template_dir, 'tables.json')
if os.path.isfile(template_file):
print("Template file already exists")
else:
shutil.copy('tables.json', template_file)
print("Template file " + template_file +" already exists")
# else:
# shutil.copy(template_file_name, template_file)
def dbConnect():
global c, db_type, db_hostname, db_user, db_password, db_name, conn
#print(db_name)
if db_type == "mysql":
import pymysql
conn = pymysql.connect(
@ -146,8 +150,15 @@ def createTables(tbl_list):
index = " PRIMARY KEY"
else:
index = ''
qwery_create = qwery_create + tbl_list[i]["fieldList"][x]["fName"] + ' ' + \
tbl_list[i]["fieldList"][x]["fType"] + index + auto_increment
fieldType = tbl_list[i]["fieldList"][x]["fType"].lower()
#print(fieldType)
if fieldType[0:3] == 'int':
qwery_create = qwery_create + tbl_list[i]["fieldList"][x]["fName"] + ' ' + \
'INTEGER' + index + auto_increment
#print(fieldType)
else:
qwery_create = qwery_create + tbl_list[i]["fieldList"][x]["fName"] + ' ' + \
tbl_list[i]["fieldList"][x]["fType"] + index + auto_increment
field_names_list.append([tbl_list[i]["fieldList"][x]["fName"], tbl_list[i]["fieldList"][x]["fDescription"]])
# struct_fields_list.append(tbl_list[i]["fieldList"][x]["fName"])
@ -167,12 +178,13 @@ def createTables(tbl_list):
i = i + 1
dbTablesDescriptionList.append(one_Table_descr)
dbTablesStructList.append(one_Table_struct)
#print(qwery_create)
print(qwery_create)
c.execute(qwery_create)
return dbTablesNamesList
def initDBstructure():
global dbTablesDescriptionList, template_file, tblNamesList
#print(template_file)
table_list = open(template_file, "r", encoding="utf-8")
data = json.load(table_list, encoding="utf-8")
tbl_list = data["tables"]
@ -502,4 +514,5 @@ def editDataIntoBD(dataList):
#initDBstructure()
firstInit()
print(template_file)
dbConnect()

0
gui.py 100644 → 100755
View File

View File

@ -1,202 +0,0 @@
{
"tables": [
{
"tableName": "users",
"tableDescription": "Пользователи",
"fieldList": [
{
"fName": "id",
"fDescription": "Номер п.п.",
"fType": "int(6)",
"index": "PRIMARY KEY",
"autoIncrement": "yes",
"relation": []
},
{
"fName": "login",
"fDescription": "Логин",
"fType": "char(20)",
"index": "yes",
"autoIncrement": "no",
"relation": []
},
{
"fName": "password",
"fDescription": "Пароль",
"fType": "char(20)",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "last_name",
"fDescription": "Фамилия",
"fType": "char(20)",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "name",
"fDescription": "Имя",
"fType": "char(20)",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "middle_name",
"fDescription": "Отчество",
"fType": "char(20)",
"index": "no",
"autoIncrement": "no",
"relation": []
}
]
},
{
"tableName": "docs",
"tableDescription": "Документы",
"fieldList": [
{
"fName": "id",
"fDescription": "Номер п.п.",
"fType": "int(6)",
"index": "PRIMARY KEY",
"autoIncrement": "yes",
"relation": []
},
{
"fName": "doc_name",
"fDescription": "Наименование",
"fType": "varchar(100)",
"index": "yes",
"autoIncrement": "no",
"relation": []
},
{
"fName": "description",
"fDescription": "Описание",
"fType": "varchar(200)",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "users_id",
"fDescription": "Владелец",
"fType": "int(6)",
"index": "no",
"autoIncrement": "no",
"relation": ["users.id", "last_name, name, middle_name"]
},
{
"fName": "parent_id",
"fDescription": "Родительский документ",
"fType": "int(6)",
"index": "no",
"autoIncrement": "no",
"relation": ["docs.id", "doc_name"]
}
]
},
{
"tableName": "address",
"tableDescription": "Адреса",
"fieldList": [
{
"fName": "id",
"fDescription": "Номер п.п.",
"fType": "int(6)",
"index": "PRIMARY KEY",
"autoIncrement": "yes",
"relation": []
},
{
"fName": "region",
"fDescription": "Регион",
"fType": "varchar(100)",
"index": "yes",
"autoIncrement": "no",
"relation": []
},
{
"fName": "city",
"fDescription": "Населеннй пункт",
"fType": "varchar(200)",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "street",
"fDescription": "Улица",
"fType": "varchar(100)",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "house",
"fDescription": "Дом",
"fType": "char(6)",
"index": "no",
"autoIncrement": "no",
"relation": []
}
]
},
{
"tableName": "test",
"tableDescription": "Шляпа",
"fieldList": [
{
"fName": "id",
"fDescription": "Номер п.п.",
"fType": "int(11)",
"index": "PRIMARY KEY",
"autoIncrement": "yes",
"relation": []
},
{
"fName": "user",
"fDescription": "Юзер шляпы",
"fType": "int(11)",
"index": "no",
"autoIncrement": "no",
"relation": ["users.id", "last_name, name, middle_name"]
}
]
},
{
"tableName": "test2",
"tableDescription": "Шляпа2",
"fieldList": [
{
"fName": "id",
"fDescription": "Номер п.п.",
"fType": "int(11)",
"index": "PRIMARY KEY",
"autoIncrement": "yes",
"relation": []
},
{
"fName": "ins_date",
"fDescription": "Дата добавления",
"fType": "DATETIME",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "user",
"fDescription": "Юзер шляпы",
"fType": "int(11)",
"index": "no",
"autoIncrement": "no",
"relation": ["users.id", "last_name, name, middle_name"]
}
]
}
]
}