Skip to content

Commit

Permalink
deciphonctl_s3_url overried
Browse files Browse the repository at this point in the history
  • Loading branch information
horta committed Oct 19, 2023
1 parent b2ffda3 commit 9df5ec9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
34 changes: 17 additions & 17 deletions control/deciphonctl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,51 @@
@hmm.command("add")
def hmm_add(hmmfile: HMMFILE, gencode: GENCODE, epsilon: EPSILON = 0.01):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.upload(hmmfile, sched.presigned.upload_hmm_post(hmmfile.name))
sched.hmm_post(HMMFile(name=hmmfile.name), gencode, epsilon)


@hmm.command("rm")
def hmm_rm(hmm_id: HMMID):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.hmm_delete(hmm_id)


@hmm.command("ls")
def hmm_ls():
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
rich.print(sched.hmm_list())


@db.command("add")
def db_add(dbfile: DBFILE, gencode: GENCODE, epsilon: EPSILON = 0.01):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.upload(dbfile, sched.presigned.upload_db_post(dbfile.name))
sched.db_post(DBFile(name=dbfile.name, gencode=gencode, epsilon=epsilon))


@db.command("rm")
def db_rm(db_id: DBID):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.db_delete(db_id)


@db.command("ls")
def db_ls():
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
rich.print(sched.db_list())


@job.command("ls")
def job_ls():
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
rich.print(sched.job_list())


Expand All @@ -128,57 +128,57 @@ def scan_add(
settings = Settings()
seqs = [Seq(name=x.id, data=x.sequence) for x in fasta_reader.Reader(fasta)]
x = Scan(db_id=db_id, multi_hits=multi_hits, hmmer3_compat=hmmer3_compat, seqs=seqs)
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.scan_post(x)


@scan.command("rm")
def scan_rm(scan_id: SCANID):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.scan_delete(scan_id)


@scan.command("ls")
def scan_ls():
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
rich.print(sched.scan_list())


@seq.command("ls")
def seq_ls():
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
rich.print(sched.seq_list())


@scan.command("snap-add")
def snap_add(scan_id: SCANID, snap: SNAPFILE):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.snap_post(scan_id, snap)


@scan.command("snap-get")
def snap_get(scan_id: SCANID, output_file: OUTFILE = Path("snap.dcs")):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
with open(output_file, "wb") as file:
file.write(sched.snap_get(scan_id))


@scan.command("snap-rm")
def snap_rm(scan_id: SCANID):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
sched.snap_delete(scan_id)


@scan.command("snap-view")
def snap_view(scan_id: SCANID):
settings = Settings()
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
print(sched.snap_view(scan_id))


Expand All @@ -191,7 +191,7 @@ def presser_run(num_workers: int = 1, log_level: LOG_LEVEL = LogLevel.info):
raise_sigint_on_sigterm()
logger.remove()
logger.add(sys.stderr, level=log_level.value.upper())
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
presser_entry(settings, sched, num_workers)


Expand All @@ -203,7 +203,7 @@ def scanner_run(
raise_sigint_on_sigterm()
logger.remove()
logger.add(sys.stderr, level=log_level.value.upper())
sched = Sched(settings.sched_url)
sched = Sched(settings.sched_url, settings.s3_url)
scanner_entry(settings, sched, num_workers, num_threads)


Expand Down
11 changes: 7 additions & 4 deletions control/deciphonctl/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import urllib.parse
from pathlib import Path
from typing import Any
from typing import Any, Optional

import requests
from deciphon_core.schema import Gencode
Expand All @@ -28,9 +28,10 @@ def __init__(self, response):


class Sched:
def __init__(self, url: HttpUrl):
def __init__(self, url: HttpUrl, s3_url: Optional[HttpUrl]):
logger.info(f"Sched URL: {url}")
self._url = url
self.s3_url = s3_url

def handle_http_response(self, response):
logger.debug(f"{response.request} {response.request.url} {response}")
Expand Down Expand Up @@ -151,11 +152,13 @@ def download_db_url(self, filename: str):

def upload_hmm_post(self, filename: str):
x = self._request(f"hmms/presigned-upload/{filename}")
return UploadPost(url=HttpUrl(x["url"]), fields=x["fields"])
url = self._sched.s3_url if self._sched.s3_url else HttpUrl(x["url"])
return UploadPost(url=url, fields=x["fields"])

def upload_db_post(self, filename: str):
x = self._request(f"dbs/presigned-upload/{filename}")
return UploadPost(url=HttpUrl(x["url"]), fields=x["fields"])
url = self._sched.s3_url if self._sched.s3_url else HttpUrl(x["url"])
return UploadPost(url=url, fields=x["fields"])


class UploadPost(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion control/deciphonctl/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import HttpUrl
from pydantic_settings import BaseSettings, SettingsConfigDict

Expand All @@ -7,7 +9,7 @@ class Settings(BaseSettings):

sched_url: HttpUrl = HttpUrl("http://localhost")

s3_url: HttpUrl = HttpUrl("http://localhost:9000")
s3_url: Optional[HttpUrl] = None
s3_bucket: str = "deciphon"

mqtt_host: str = "localhost"
Expand Down

0 comments on commit 9df5ec9

Please sign in to comment.