
import os

import luigi
from luigi import LocalTarget

from tasks.config import db
from tasks.config import output

from rnacentral.db import cursor
from rnacentral.search import exporter


class SearchChunkTask(luigi.Task):  # pylint: disable=R0904
    """
    This is a task that will create an xml export for the given range of UPI's.
    """

    min = luigi.IntParameter()
    max = luigi.IntParameter()

    def output(self):
        config = output()
        filepattern = 'xml_export_{min}_{max}.xml'.format(
            min=self.min,
            max=self.max,
        )
        filename = os.path.join(config.search_files, filepattern)
        return LocalTarget(filename)

    def run(self):
        with self.output().open('w') as raw:
            with cursor(db()) as cur:
                results = exporter.range(cur, self.min, self.max)
                exporter.write(raw, results)


import os

import luigi
from luigi import LocalTarget

from tasks.config import db
from tasks.config import output

from rnacentral.search import exporter


class SearchChunkTask(luigi.Task):  # pylint: disable=R0904
    """
    This is a task that will create an xml export for the given range of UPI's.
    """

    min = luigi.IntParameter()
    max = luigi.IntParameter()

    def output(self):
        config = output()
        filepattern = 'xml_export_{min}_{max}.xml'.format(
            min=self.min,
            max=self.max,
        )
        filename = os.path.join(config.search_files, filepattern)
        return LocalTarget(filename)

    def run(self):
        with self.output().open('w') as raw:
            results = exporter.range(db(), self.min, self.max)
            exporter.write(raw, results)

Use new psql based export
Use new psql based export

This changes the function arguments to use.

  
  import os
  
  import luigi
  from luigi import LocalTarget
  
  from tasks.config import db
  from tasks.config import output
  
- from rnacentral.db import cursor
  from rnacentral.search import exporter
  
  
  class SearchChunkTask(luigi.Task):  # pylint: disable=R0904
      """
      This is a task that will create an xml export for the given range of UPI's.
      """
  
      min = luigi.IntParameter()
      max = luigi.IntParameter()
  
      def output(self):
          config = output()
          filepattern = 'xml_export_{min}_{max}.xml'.format(
              min=self.min,
              max=self.max,
          )
          filename = os.path.join(config.search_files, filepattern)
          return LocalTarget(filename)
  
      def run(self):
          with self.output().open('w') as raw:
-             with cursor(db()) as cur:
-                 results = exporter.range(cur, self.min, self.max)
+             results = exporter.range(db(), self.min, self.max)
-                 exporter.write(raw, results)
+             exporter.write(raw, results)
  
Use new psql based export
## Code Before:

import os

import luigi
from luigi import LocalTarget

from tasks.config import db
from tasks.config import output

from rnacentral.db import cursor
from rnacentral.search import exporter


class SearchChunkTask(luigi.Task):  # pylint: disable=R0904
    """
    This is a task that will create an xml export for the given range of UPI's.
    """

    min = luigi.IntParameter()
    max = luigi.IntParameter()

    def output(self):
        config = output()
        filepattern = 'xml_export_{min}_{max}.xml'.format(
            min=self.min,
            max=self.max,
        )
        filename = os.path.join(config.search_files, filepattern)
        return LocalTarget(filename)

    def run(self):
        with self.output().open('w') as raw:
            with cursor(db()) as cur:
                results = exporter.range(cur, self.min, self.max)
                exporter.write(raw, results)

## Instruction:
Use new psql based export
## Code After:

import os

import luigi
from luigi import LocalTarget

from tasks.config import db
from tasks.config import output

from rnacentral.search import exporter


class SearchChunkTask(luigi.Task):  # pylint: disable=R0904
    """
    This is a task that will create an xml export for the given range of UPI's.
    """

    min = luigi.IntParameter()
    max = luigi.IntParameter()

    def output(self):
        config = output()
        filepattern = 'xml_export_{min}_{max}.xml'.format(
            min=self.min,
            max=self.max,
        )
        filename = os.path.join(config.search_files, filepattern)
        return LocalTarget(filename)

    def run(self):
        with self.output().open('w') as raw:
            results = exporter.range(db(), self.min, self.max)
            exporter.write(raw, results)
