
import glob
import os
import requests

import stoneridge

class StoneRidgeUploader(object):
    """Takes the upload files created by the collator and uploads them to the
    graph server
    """
    def __init__(self):
        self.url = stoneridge.get_config('upload', 'url')

    def run(self):
        file_pattern = os.path.join(stoneridge.outdir, 'upload_*.json')
        upload_files = glob.glob(file_pattern)
        files = {os.path.basename(fname): open(fname, 'rb')
                 for fname in upload_files}
        requests.post(self.url, files=files)
        for f in files.values():
            f.close()

@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    args = parser.parse_args()

    uploader = StoneRidgeUploader()
    uploader.run()


import glob
import os
import requests

import stoneridge

class StoneRidgeUploader(object):
    """Takes the upload files created by the collator and uploads them to the
    graph server
    """
    def __init__(self):
        self.url = stoneridge.get_config('upload', 'url')

    def run(self):
        file_pattern = os.path.join(stoneridge.outdir, 'upload_*.json')
        upload_files = glob.glob(file_pattern)
        if not upload_files:
            # Nothing to do, so forget it!
            return
        files = {os.path.basename(fname): open(fname, 'rb')
                 for fname in upload_files}
        requests.post(self.url, files=files)
        for f in files.values():
            f.close()

@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    args = parser.parse_args()

    uploader = StoneRidgeUploader()
    uploader.run()

Fix uploader when there is nothing to upload
Fix uploader when there is nothing to upload

  
  import glob
  import os
  import requests
  
  import stoneridge
  
  class StoneRidgeUploader(object):
      """Takes the upload files created by the collator and uploads them to the
      graph server
      """
      def __init__(self):
          self.url = stoneridge.get_config('upload', 'url')
  
      def run(self):
          file_pattern = os.path.join(stoneridge.outdir, 'upload_*.json')
          upload_files = glob.glob(file_pattern)
+         if not upload_files:
+             # Nothing to do, so forget it!
+             return
          files = {os.path.basename(fname): open(fname, 'rb')
                   for fname in upload_files}
          requests.post(self.url, files=files)
          for f in files.values():
              f.close()
  
  @stoneridge.main
  def main():
      parser = stoneridge.ArgumentParser()
      args = parser.parse_args()
  
      uploader = StoneRidgeUploader()
      uploader.run()
  
Fix uploader when there is nothing to upload
## Code Before:

import glob
import os
import requests

import stoneridge

class StoneRidgeUploader(object):
    """Takes the upload files created by the collator and uploads them to the
    graph server
    """
    def __init__(self):
        self.url = stoneridge.get_config('upload', 'url')

    def run(self):
        file_pattern = os.path.join(stoneridge.outdir, 'upload_*.json')
        upload_files = glob.glob(file_pattern)
        files = {os.path.basename(fname): open(fname, 'rb')
                 for fname in upload_files}
        requests.post(self.url, files=files)
        for f in files.values():
            f.close()

@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    args = parser.parse_args()

    uploader = StoneRidgeUploader()
    uploader.run()

## Instruction:
Fix uploader when there is nothing to upload
## Code After:

import glob
import os
import requests

import stoneridge

class StoneRidgeUploader(object):
    """Takes the upload files created by the collator and uploads them to the
    graph server
    """
    def __init__(self):
        self.url = stoneridge.get_config('upload', 'url')

    def run(self):
        file_pattern = os.path.join(stoneridge.outdir, 'upload_*.json')
        upload_files = glob.glob(file_pattern)
        if not upload_files:
            # Nothing to do, so forget it!
            return
        files = {os.path.basename(fname): open(fname, 'rb')
                 for fname in upload_files}
        requests.post(self.url, files=files)
        for f in files.values():
            f.close()

@stoneridge.main
def main():
    parser = stoneridge.ArgumentParser()
    args = parser.parse_args()

    uploader = StoneRidgeUploader()
    uploader.run()
