Compare commits
2 Commits
5b17bba5bf
...
3fd2ec4762
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fd2ec4762 | ||
|
|
36e23465a8 |
3
db.py
3
db.py
@@ -2,6 +2,7 @@ from datetime import datetime
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from sqlalchemy import create_engine, String, select, ForeignKey, Enum
|
from sqlalchemy import create_engine, String, select, ForeignKey, Enum
|
||||||
from sqlalchemy.orm import Session, DeclarativeBase, Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Session, DeclarativeBase, Mapped, mapped_column, relationship
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
def tow(day: int, hour: int, minute: int):
|
def tow(day: int, hour: int, minute: int):
|
||||||
@@ -133,4 +134,4 @@ class Schemas(Base):
|
|||||||
|
|
||||||
|
|
||||||
def connect_db():
|
def connect_db():
|
||||||
return create_engine("postgresql+psycopg://postgres:Root12345678@10.10.8.83:32101/db")
|
return create_engine(f"postgresql+psycopg://{Config.pg_username}:{Config.pg_password}@{Config.pg_host}:{Config.pg_port}/{Config.pg_dbname}")
|
||||||
|
|||||||
18
main.py
18
main.py
@@ -12,6 +12,7 @@ from xmlrpc.server import SimpleXMLRPCServer
|
|||||||
from xmlrpc.client import ServerProxy
|
from xmlrpc.client import ServerProxy
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import io
|
||||||
import zlib
|
import zlib
|
||||||
import os.path
|
import os.path
|
||||||
import requests
|
import requests
|
||||||
@@ -70,7 +71,6 @@ def run_tasks():
|
|||||||
|
|
||||||
def replication_task():
|
def replication_task():
|
||||||
while True:
|
while True:
|
||||||
print()
|
|
||||||
conn = db.connect_db()
|
conn = db.connect_db()
|
||||||
with Session(conn) as session:
|
with Session(conn) as session:
|
||||||
for bndname in connected:
|
for bndname in connected:
|
||||||
@@ -241,7 +241,7 @@ def replication(bnd_name: str, commit_id: str, schema: str):
|
|||||||
ET.SubElement(res, 'replication', {'id': commit_id, 'scheme': schema})
|
ET.SubElement(res, 'replication', {'id': commit_id, 'scheme': schema})
|
||||||
response_params = {
|
response_params = {
|
||||||
'from': f'tcp://{Config.self_bnd}',
|
'from': f'tcp://{Config.self_bnd}',
|
||||||
'to': f'tcp://{Config.remote_bnd}',
|
'to': f'tcp://{bnd_name}',
|
||||||
'ts_added': date.timestamp(),
|
'ts_added': date.timestamp(),
|
||||||
'user_id': '0',
|
'user_id': '0',
|
||||||
'query_type': NEW_REPLICATION_REQUEST,
|
'query_type': NEW_REPLICATION_REQUEST,
|
||||||
@@ -540,18 +540,20 @@ def put_object(params, files, url):
|
|||||||
|
|
||||||
|
|
||||||
def apply_commits(params, files, url):
|
def apply_commits(params, files, url):
|
||||||
logger.warning(params, files, url)
|
logger.warning(params)
|
||||||
assert len(files) == 1
|
assert len(files) == 1
|
||||||
file = files[0]
|
file = files[0]
|
||||||
|
logger.warning(file)
|
||||||
dir = TemporaryDirectory()
|
dir = TemporaryDirectory()
|
||||||
with zipfile.ZipFile(file, 'r') as zip_ref:
|
r = requests.get(file['url'])
|
||||||
|
with zipfile.ZipFile(io.BytesIO(r.content)) as zip_ref:
|
||||||
zip_ref.extractall(dir.name)
|
zip_ref.extractall(dir.name)
|
||||||
req = ET.fromstring(params['query_data'])
|
req = ET.fromstring(params['query_data'])
|
||||||
repl = req.find('replication')
|
repl = req.find('replication')
|
||||||
scheme = repl.get('scheme')
|
scheme = repl.get('scheme')
|
||||||
commit = repl.get('id')
|
commit = repl.get('id')
|
||||||
logger.warning(scheme, commit)
|
logger.warning(scheme)
|
||||||
os.path.join(dir.name, 'export.o5c')
|
logger.warning(commit)
|
||||||
con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
|
con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
|
||||||
Config.oodb_username, Config.oodb_passwd, scheme)
|
Config.oodb_username, Config.oodb_passwd, scheme)
|
||||||
ws = OODBWorkspace.ws(scheme)
|
ws = OODBWorkspace.ws(scheme)
|
||||||
@@ -561,10 +563,10 @@ def apply_commits(params, files, url):
|
|||||||
oe = IpdExporter(ws)
|
oe = IpdExporter(ws)
|
||||||
oe.improtFromOsm(os.path.join(dir.name, 'export.o5c'))
|
oe.improtFromOsm(os.path.join(dir.name, 'export.o5c'))
|
||||||
oe.improtFromMbtiles(os.path.join(dir.name, 'export.mbtiles'))
|
oe.improtFromMbtiles(os.path.join(dir.name, 'export.mbtiles'))
|
||||||
with open('export_files.json', 'r') as f:
|
with open(os.path.join(dir.name, 'export_files.json'), 'r') as f:
|
||||||
files_data = json.load(f)
|
files_data = json.load(f)
|
||||||
for file_data in files_data:
|
for file_data in files_data:
|
||||||
upload_file(file_data['filename'], file_data['key'], file_data['bucket'])
|
upload_file(os.path.join(dir.name, file_data['key']), file_data['key'], file_data['bucket'])
|
||||||
|
|
||||||
|
|
||||||
def run_task(query_type, params, files, url):
|
def run_task(query_type, params, files, url):
|
||||||
|
|||||||
Reference in New Issue
Block a user