from indra.tools.reading.readers.core import EmptyReader

from indra.sources import trips


class TripsReader(EmptyReader):
    """A stand-in for TRIPS reading.

    Currently, we do not run TRIPS (more specifically DRUM) regularly at large
    scales, however on occasion we have outputs from TRIPS that were generated
    a while ago.
    """
    name = 'TRIPS'

    def __init__(self, *args, **kwargs):
        self.version = self.get_version()
        return

    def _read(self, *args, **kwargs):
        return []

    @classmethod
    def get_version(cls):
        return 'STATIC'

    @staticmethod
    def get_processor(content):
        return trips.process_xml(content)




import os
import subprocess as sp

from indra.tools.reading.readers.core import Reader

from indra.sources.trips import client, process_xml
from indra_db import formats


class TripsReader(Reader):
    """A stand-in for TRIPS reading.

    Currently, we do not run TRIPS (more specifically DRUM) regularly at large
    scales, however on occasion we have outputs from TRIPS that were generated
    a while ago.
    """
    name = 'TRIPS'
    result_format = formats.XML

    def __init__(self, *args, **kwargs):
        self.version = self.get_version()
        return

    def _read(self, content_iter, verbose=False, log=False, n_per_proc=None):
        # Start trips running
        if os.environ.get("IN_TRIPS_DOCKER", 'false') != 'true':
            return []

        p = sp.Popen('/sw/drum/bin/startup.sh', stdout=sp.PIPE,
                     stderr=sp.STDOUT)
        service_endpoint = 'http://localhost:80/cgi/'
        service_host = 'drum'

        # Process all the content.
        for content in content_iter:
            html = client.send_query(content.get_text(),
                                     service_endpoint=service_endpoint,
                                     service_host=service_host)
            xml = client.get_xml(html)
            self.add_result(content.get_id(), xml)

        return self.results

    @classmethod
    def get_version(cls):
        return 'STATIC'

    @staticmethod
    def get_processor(reading_content):
        return process_xml(reading_content)




Implement the basics of the TRIPS reader.
Implement the basics of the TRIPS reader.

- from indra.tools.reading.readers.core import EmptyReader
+ import os
+ import subprocess as sp
  
- from indra.sources import trips
+ from indra.tools.reading.readers.core import Reader
+ 
+ from indra.sources.trips import client, process_xml
+ from indra_db import formats
  
  
- class TripsReader(EmptyReader):
+ class TripsReader(Reader):
      """A stand-in for TRIPS reading.
  
      Currently, we do not run TRIPS (more specifically DRUM) regularly at large
      scales, however on occasion we have outputs from TRIPS that were generated
      a while ago.
      """
      name = 'TRIPS'
+     result_format = formats.XML
  
      def __init__(self, *args, **kwargs):
          self.version = self.get_version()
          return
  
-     def _read(self, *args, **kwargs):
+     def _read(self, content_iter, verbose=False, log=False, n_per_proc=None):
+         # Start trips running
+         if os.environ.get("IN_TRIPS_DOCKER", 'false') != 'true':
-         return []
+             return []
+ 
+         p = sp.Popen('/sw/drum/bin/startup.sh', stdout=sp.PIPE,
+                      stderr=sp.STDOUT)
+         service_endpoint = 'http://localhost:80/cgi/'
+         service_host = 'drum'
+ 
+         # Process all the content.
+         for content in content_iter:
+             html = client.send_query(content.get_text(),
+                                      service_endpoint=service_endpoint,
+                                      service_host=service_host)
+             xml = client.get_xml(html)
+             self.add_result(content.get_id(), xml)
+ 
+         return self.results
  
      @classmethod
      def get_version(cls):
          return 'STATIC'
  
      @staticmethod
-     def get_processor(content):
+     def get_processor(reading_content):
-         return trips.process_xml(content)
+         return process_xml(reading_content)
  
  
  
  
Implement the basics of the TRIPS reader.
## Code Before:
from indra.tools.reading.readers.core import EmptyReader

from indra.sources import trips


class TripsReader(EmptyReader):
    """A stand-in for TRIPS reading.

    Currently, we do not run TRIPS (more specifically DRUM) regularly at large
    scales, however on occasion we have outputs from TRIPS that were generated
    a while ago.
    """
    name = 'TRIPS'

    def __init__(self, *args, **kwargs):
        self.version = self.get_version()
        return

    def _read(self, *args, **kwargs):
        return []

    @classmethod
    def get_version(cls):
        return 'STATIC'

    @staticmethod
    def get_processor(content):
        return trips.process_xml(content)




## Instruction:
Implement the basics of the TRIPS reader.
## Code After:
import os
import subprocess as sp

from indra.tools.reading.readers.core import Reader

from indra.sources.trips import client, process_xml
from indra_db import formats


class TripsReader(Reader):
    """A stand-in for TRIPS reading.

    Currently, we do not run TRIPS (more specifically DRUM) regularly at large
    scales, however on occasion we have outputs from TRIPS that were generated
    a while ago.
    """
    name = 'TRIPS'
    result_format = formats.XML

    def __init__(self, *args, **kwargs):
        self.version = self.get_version()
        return

    def _read(self, content_iter, verbose=False, log=False, n_per_proc=None):
        # Start trips running
        if os.environ.get("IN_TRIPS_DOCKER", 'false') != 'true':
            return []

        p = sp.Popen('/sw/drum/bin/startup.sh', stdout=sp.PIPE,
                     stderr=sp.STDOUT)
        service_endpoint = 'http://localhost:80/cgi/'
        service_host = 'drum'

        # Process all the content.
        for content in content_iter:
            html = client.send_query(content.get_text(),
                                     service_endpoint=service_endpoint,
                                     service_host=service_host)
            xml = client.get_xml(html)
            self.add_result(content.get_id(), xml)

        return self.results

    @classmethod
    def get_version(cls):
        return 'STATIC'

    @staticmethod
    def get_processor(reading_content):
        return process_xml(reading_content)



