From a25a54eb928fbf3d1b981c7b41d273f0ee3537ee Mon Sep 17 00:00:00 2001 From: Ivan Vazhenin Date: Wed, 15 Nov 2023 10:58:45 +0700 Subject: [PATCH] Create dockerfile, changed apply_commits method --- Dockerfile | 12 ++++++++++++ db.py | 13 ++++++++++--- infra.py | 9 +++++++++ main.py | 14 ++++++++------ requirements.txt | 1 - test.py | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 Dockerfile create mode 100644 infra.py create mode 100644 test.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3bd8046 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM reg.ivazh.ru/infra-oodb +WORKDIR /app +COPY . ./ +RUN cd deps/pygost-5.12/ && \ + python3 setup.py install && \ + cd ../.. && \ + pip3 install -r requirements.txt +ENV LD_LIBRARY_PATH "/app" +ENV PYTHONPATH "${PYTHONPATH}:/app" +EXPOSE 9000 +EXPOSE 80 +CMD ["python3", "main.py"] diff --git a/db.py b/db.py index c3447ce..524784b 100644 --- a/db.py +++ b/db.py @@ -54,6 +54,7 @@ class User(Base): 'profiles': [x.to_dict() for x in self.profiles], 'schedule': [x.to_dict() for x in self.schedule], 'queue': [x.to_dict() for x in self.queue], + 'income_branches': [x.to_dict() for x in self.income_branches], } def is_active_now(self): @@ -74,8 +75,8 @@ class Profile(Base): id: Mapped[int] = mapped_column(primary_key=True) user_id: Mapped[int] = mapped_column(ForeignKey('users.id')) scheme: Mapped[str] - branch: Mapped[str] - json: Mapped[str] + branch: Mapped[str] = mapped_column(String, nullable=True) + json: Mapped[str] = mapped_column(String, nullable=True) user: Mapped['User'] = relationship(back_populates='profiles') @@ -84,7 +85,6 @@ class Profile(Base): 'id': self.id, 'scheme': self.scheme, 'branch': self.branch, - 'upstream': self.upstream, 'json': self.json, } @@ -99,6 +99,13 @@ class IncomeBranch(Base): user: Mapped['User'] = relationship(back_populates='income_branches') + def to_dict(self) -> dict: + return { + 'id': self.id, + 'scheme': self.scheme, + 'branch': self.branch, + } + class Schedule(Base): __tablename__ = 'schedule' diff --git a/infra.py b/infra.py new file mode 100644 index 0000000..11d1e52 --- /dev/null +++ b/infra.py @@ -0,0 +1,9 @@ +from libcommon import * +from libdatabase import * +from libgeodata import * +from libgeodriver import * +from libgeodesy import * +from libgeom import * +from libipdutilities import * +from liboodriver import * + diff --git a/main.py b/main.py index f7bb7b9..6aff4bf 100644 --- a/main.py +++ b/main.py @@ -564,12 +564,14 @@ def apply_commits(params, files, url): res = ws.init(con) logger.warning(res) oe = IpdExporter(ws) - oe.improtFromOsm(os.path.join(dir.name, 'export.o5c')) - oe.improtFromMbtiles(os.path.join(dir.name, 'export.mbtiles')) - with open(os.path.join(dir.name, 'export_files.json'), 'r') as f: - files_data = json.load(f) - for file_data in files_data: - upload_file(os.path.join(dir.name, file_data['key']), file_data['key'], file_data['bucket']) + if not oe.importChanges(os.path.join(dir.name, 'export.o5c'), os.path.join(dir.name, 'export.mbtiles')): + logging.warning(f'Error importing commit {commit}: {oe.lastError().text()}') + else: + logging.warning(f'Importing commit {commit} finished successfully') + with open(os.path.join(dir.name, 'export_files.json'), 'r') as f: + files_data = json.load(f) + for file_data in files_data: + upload_file(os.path.join(dir.name, file_data['key']), file_data['key'], file_data['bucket']) ws.clearData(True) diff --git a/requirements.txt b/requirements.txt index 060ca86..8ecf94b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,6 @@ graphql-core==3.3.0a3 greenlet==2.0.2 h11==0.14.0 idna==3.4 -infra jmespath==1.0.1 multidict==6.0.4 pika==1.3.2 diff --git a/test.py b/test.py new file mode 100644 index 0000000..160d5ca --- /dev/null +++ b/test.py @@ -0,0 +1,32 @@ +import db +from sqlalchemy.orm import Session + + +def get_branch(bndname: str, scheme: str): + conn = db.connect_db() + with Session(conn) as session: + item = session.query(db.IncomeBranch).filter_by(scheme=scheme).join(db.User).filter_by(bndname=bndname).one_or_none() + if item: + return item.branch + return None + + +def is_replication_scheme(bndname: str, scheme: str): + conn = db.connect_db() + with Session(conn) as session: + item = session.query(db.User).filter_by(bndname=bndname).one_or_none() + if not item: + return False + profiles = {x.scheme: x.to_dict() for x in item.profiles} + if len(profiles) == 0 or scheme in profiles: + return True + return False + + +def main(): + # print(get_branch('bnd128', 'ood')) + print(is_replication_scheme('bnd128', 'documents_src')) + + +if __name__ == '__main__': + main() \ No newline at end of file