Created
April 30, 2014 12:48
-
-
Save miku/4d7e9589e63182f88509 to your computer and use it in GitHub Desktop.
Self contained FTPMirror example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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