Skip to content

Instantly share code, notes, and snippets.

@miku
Created April 30, 2014 12:48
Show Gist options
  • Save miku/4d7e9589e63182f88509 to your computer and use it in GitHub Desktop.
Save miku/4d7e9589e63182f88509 to your computer and use it in GitHub Desktop.
Self contained FTPMirror example.
#!/usr/bin/env
# coding: utf-8
"""
Example FTPMirror task. On the command line:
$ python ftpmirror-example.py MirrorTask --local-scheduler
Example output:
/tmp/T/common/FTPMirror/e4a5338cb2000004928cf029e666a4024e40a798/cs00-02.pdf
/tmp/T/common/FTPMirror/e4a5338cb2000004928cf029e666a4024e40a798/cs00-03.pdf
/tmp/T/common/FTPMirror/e4a5338cb2000004928cf029e666a4024e40a798/cs00-06.pdf
/tmp/T/common/FTPMirror/e4a5338cb2000004928cf029e666a4024e40a798/cs00-07.pdf
/tmp/T/common/FTPMirror/e4a5338cb2000004928cf029e666a4024e40a798/cs00-08.pdf
"""
from gluish.common import FTPMirror
from gluish.task import BaseTask
from gluish.utils import random_string
import datetime
import luigi
import tempfile
class DefaultTask(BaseTask):
""" Some default abstract task for your tasks. BASE and TAG determine
the paths, where the artefacts will be stored. """
BASE = tempfile.gettempdir()
TAG = 'just-a-test'
class MirrorTask(DefaultTask):
""" Indicator make this task run on each test run. """
indicator = luigi.Parameter(default=random_string())
def requires(self):
return FTPMirror(host='ftp.cs.brown.edu',
username='anonymous', password='anonymous',
pattern='*pdf', base='/pub/techreports/00')
def run(self):
self.input().move(self.output().path)
print("Wrote receipt to: %s" % self.output().path)
def output(self):
return luigi.LocalTarget(path=self.path())
if __name__ == '__main__':
luigi.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment