Skip to content

Commit

Permalink
Merge branch 'ragic' of github.com:EdinburghGenomics/illuminatus into…
Browse files Browse the repository at this point in the history
… ragic
  • Loading branch information
tbooth committed Oct 29, 2024
2 parents 14086e0 + e3f3ca4 commit a53b823
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions illuminatus/ragic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import urllib.request
import configparser
import json
import shutil
from pprint import pprint, pformat

import logging
Expand All @@ -12,7 +13,8 @@
# Basic client for the Ragic API - see
# https://github.com/ragic/public/blob/master/HTTP%20API%20Sample/Python-Sample/read.py
# This client has no extra dependencies - just Py3 standard lib
USE_RAGIC = (os.environ.get("USE_RAGIC") == "yes")
def use_ragic():
return os.environ.get("USE_RAGIC") == "yes"

# IDs for fields in my database
# Still not sure if there is a way to introspect the field number to name mapping??
Expand Down Expand Up @@ -144,7 +146,7 @@ def connect_with_creds(cls, ini_section="ragic"):
"""Use ~/.ragic_api to connect
"""
# Master switch for this, because I don't want any tests to be connecting to Ragic.
if not USE_RAGIC:
if not use_ragic():
raise RuntimeError("Ragic is turned off. Set USE_RAGIC=yes to enable it.")

config = configparser.SafeConfigParser()
Expand Down Expand Up @@ -215,6 +217,30 @@ def post_update(self, sheet, record_id, update_items):

return json_resp

def get_data_dict(self, destfile):
"""Download the data dictionary
HTML will be saved out to destfile
"""
# TODO - this is just messing around at the moment. We get the data dictionary
# as a human-readable HTML page. Ideally we want this as JSON, but scraping it
# for the field names and numbers is going to be pretty easy. The idea would be that
# I could then dump the forms dict to a JSON file rather than manually adding it at the
# top of the code here.
url = f"{self.server_url}/sims/doc.jsp?a={self.account_name}"
req = urllib.request.Request( method = "GET",
url = url,
headers = self._get_headers() )
with urllib.request.urlopen( url = req,
timeout = self.http_timeout ) as resp:
if resp.status != 200:
raise RequestError(f"{resp.status} {resp.reason}")

with open(destfile, "wb") as dfh:
shutil.copyfileobj(resp, dfh)

return resp.status

def _munge_query(self, query, mapping):
"""Fix queries where the first part is a named field by using the mapping.
"""
Expand Down

0 comments on commit a53b823

Please sign in to comment.