コード例 #1
0
def melts_query(data_dict, url_sfx="Compute"):
    """
    Execute query against the MELTS web services.

    Parameters
    ----------
    data_dict : :class:`dict`
        Dictionary containing data to be sent to the web query.
    url_sfx : :class:`str`, :code:`Compute`
        URL suffix to denote specific web service (Compute | Oxides | Phases).

    Returns
    --------
    :class:`dict`
        Dictionary containing results.
    """
    try:
        assert internet_connection()
        url = "http://thermofit.ofm-research.org:8080/multiMELTSWSBxApp/" + url_sfx
        xmldata = dicttoxml.dicttoxml(data_dict,
                                      custom_root="MELTSinput",
                                      root=True,
                                      attr_type=False)
        headers = {"content-type": "text/xml", "data-type": "xml"}
        resp = requests.post(url, data=xmldata, headers=headers)
        resp.raise_for_status()
        result = xmljson.parker.data(ET.fromstring(resp.text))
        return result
    except AssertionError:
        raise AssertionError("Must be connected to the internet to run query.")
コード例 #2
0
def download_melts(directory, version=None):
    """
    Download and extract melts zip file to a given directory.

    Parameters
    ----------
    directory :  :class:`str` |  :class:`pathlib.Path`
        Directory into which to extract melts.
    version : :class:`str`
        Which alphamelts version to use. Defaults to latest stable version.

    Todo
    -----
        * Check version, enable update-style overwrite
    """
    try:
        assert internet_connection()
        system = platform.system()
        release = platform.release()
        platver = platform.version()
        bits, linkage = platform.architecture()
        bits = bits[:2]
        if version is None:
            version = 1.9  # eventually should update this programatically!
        mver = "-".join(str(version).split("."))
        zipsource = "https://magmasource.caltech.edu/alphamelts/zipfiles/"
        if system == "Linux":
            if ("Microsoft" in release) or ("Microsoft" in platver):
                url = zipsource + "wsl_alphamelts_{}.zip".format(mver)
            else:
                url = zipsource + "linux_alphamelts_{}.zip".format(mver)
        elif system == "Darwin":
            url = zipsource + "macosx_alphamelts_{}.zip".format(mver)
        elif system == "Windows":
            url = zipsource + "windows_alphamelts_{}.zip".format(mver)
            install_file = "alphamelts_win{}.exe".format(bits)
        else:
            raise NotImplementedError("System unknown: {}".format(system))

        # Set install directory for .bat files
        directory = Path(directory)
        if directory:
            install_dir = directory
        else:
            install_dir = "."

        if not install_dir.exists():
            install_dir.mkdir(parents=True)

        r = requests.get(url, stream=True)
        if r.ok:
            z = zipfile.ZipFile(io.BytesIO(r.content))
            extract_zip(z, install_dir)
    except AssertionError:
        raise AssertionError("Need an internet connection to download.")
コード例 #3
0
ファイル: util_web.py プロジェクト: morganjwilliams/pyrolite
 def test_insecure(self):
     internet_connection(secure=False)
コード例 #4
0
ファイル: util_web.py プロジェクト: morganjwilliams/pyrolite
 def test_default(self):
     internet_connection()
コード例 #5
0
import unittest
from pyrolite.util.web import internet_connection
from pyrolite_meltsutil.util.synthetic import default_data_dictionary
from pyrolite_meltsutil.web import *


# @unittest.skip("Web service down.")
@unittest.skipIf(not internet_connection(), "Needs internet connection.")
class TestWebService(unittest.TestCase):
    """Tests the current MELTS webservice interactivity with default data."""
    def setUp(self):
        self.dict = default_data_dictionary()

    def test_melts_compute(self):
        """Tests the MELTS-compute web service."""
        result = melts_compute(self.dict)

    def test_melts_oxides(self):
        """Tests the MELTS-oxides web service."""
        result = melts_oxides(self.dict)

    def test_melts_phases(self):
        """Tests the MELTS-phases web service."""
        result = melts_phases(self.dict)


if __name__ == "__main__":
    unittest.main()