-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from gabrielbazan/development
Publication on FTP Repositories
- Loading branch information
Showing
37 changed files
with
464 additions
and
161 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from ftplib import FTP | ||
|
||
|
||
class Ftp(object): | ||
|
||
def __init__(self, ip, username, password, timeout): | ||
self.connection = FTP(ip, timeout=timeout) | ||
self.connection.login(user=username, passwd=password) | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, kind, value, tb): | ||
self.close() | ||
|
||
def close(self): | ||
self.connection.quit() | ||
|
||
def upload_file(self, local_path, remote_path): | ||
self.connection.storbinary('STOR ' + remote_path, open(local_path, 'rb')) | ||
|
||
def create_directory_if_not_exists(self, path): | ||
if not self.directory_exists(path): | ||
self.create_directory(path) | ||
|
||
def directory_exists(self, path): | ||
current_path = self.connection.pwd() | ||
exists = True | ||
try: | ||
self.connection.cwd(path) | ||
except Exception: | ||
exists = False | ||
finally: | ||
self.connection.cwd(current_path) | ||
return exists | ||
|
||
def create_directory(self, path): | ||
self.connection.mkd(path) |
10 changes: 9 additions & 1 deletion
10
lycheepy/worker/worker/gateways/repository/ftp_repository.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
from os.path import join, basename | ||
from repository import Repository | ||
from ftp import Ftp | ||
|
||
|
||
class FtpRepository(Repository): | ||
|
||
def publish(self, name, raster_file): pass | ||
def __init__(self, ip, username, password, timeout): | ||
self.connection = Ftp(ip, username, password, timeout) | ||
|
||
def publish(self, name, raster_file): | ||
with self.connection: | ||
self.connection.create_directory_if_not_exists(name) | ||
self.connection.upload_file(raster_file, join(name, basename(raster_file))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
[logging] | ||
level=INFO |
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
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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from processes import ProcessesGateway | ||
from chains import ChainsGateway | ||
from executions import ExecutionsGateway | ||
from wps import WpsGateway | ||
from csw import CswGateway |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from requests import get, post, put, delete | ||
|
||
|
||
class ChainsGateway(object): | ||
|
||
def __init__(self, uri): | ||
self.uri = uri | ||
|
||
def list(self): | ||
return get(self.uri) | ||
|
||
def create(self, specification): | ||
return post(self.uri, json=specification) | ||
|
||
def get(self, identifier): | ||
return get('{}/{}'.format(self.uri, identifier)) | ||
|
||
def update(self, identifier, specification, process_file): | ||
pass | ||
|
||
def delete(self, identifier): | ||
return delete('{}/{}'.format(self.uri, identifier)) | ||
|
||
def exists(self, identifier): | ||
response = get('{}?identifier__eq={}'.format(self.uri, identifier)) | ||
assert response.status_code == 200, 'Failed to query chain' | ||
return response.json().get('results') |
Oops, something went wrong.