From 82ab4700e2b6baa46593a4d75b04420629708d90 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Thu, 12 Mar 2015 17:27:05 +0100 Subject: [PATCH] Relative import --- external_file_location/location.py | 4 +- external_file_location/task.py | 4 +- external_file_location/tasks/ftp_backup.py | 58 ---------------------- 3 files changed, 4 insertions(+), 62 deletions(-) delete mode 100755 external_file_location/tasks/ftp_backup.py diff --git a/external_file_location/location.py b/external_file_location/location.py index 8d26e462..1205a5d2 100644 --- a/external_file_location/location.py +++ b/external_file_location/location.py @@ -21,8 +21,8 @@ ############################################################################### from openerp import models, fields -from abstract_task import AbstractTask -from helper import itersubclasses +from knowledge.external_file_location.abstract_task import AbstractTask +from knowledge.external_file_location.helper import itersubclasses class Location(models.Model): _name = 'external.file.location' diff --git a/external_file_location/task.py b/external_file_location/task.py index c7803056..023faae1 100644 --- a/external_file_location/task.py +++ b/external_file_location/task.py @@ -21,8 +21,8 @@ ############################################################################### from openerp import models, fields, api -from helper import itersubclasses -from abstract_task import AbstractTask +from knowledge.external_file_location.helper import itersubclasses +from knowledge.external_file_location.abstract_task import AbstractTask class Task(models.Model): diff --git a/external_file_location/tasks/ftp_backup.py b/external_file_location/tasks/ftp_backup.py deleted file mode 100755 index 7316b81f..00000000 --- a/external_file_location/tasks/ftp_backup.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - - -import sys -import os -from tempfile import TemporaryFile -from ftplib import FTP - -class FTPConnection(object): - - def __init__(self, host, user, pwd, port=None, allow_dir_creation=False): - super(FTPConnection, self).__init__(host, user, pwd, port, allow_dir_creation) - if not port: - self.port = 21 - self.protocol = "FTP" - - def connect(self): - self.connection = FTP(self.location, self.port) - self.connection.login(self.user, self.pwd) - - def close(self): - self.connection.close() - - def get(self, filename, path=None): - if path: - filepath = "{}/{}".format(path, filename) - else: - filepath = filename - outfile = TemporaryFile('w+b') - self.connection.retrbinary('RETR ' + filepath, outfile.write) - return outfile - - def put(self, fileobject, filename, path=None): - if path: - filepath = "{}/{}".format(path, filename) - else: - filepath = filename - self.connection.storbinary('STOR ' + filepath, fileobject) - return True - - def search(self, filename, path=None): - if path: - filepath = "{}/{}".format(path, filename) - else: - filepath = filename - connection_list_result = self.connection.nlst() - return [x for x in connection_list_result if filename in x] - - - def move(self, filename, oldpath, newpath): - self.connection.rename( - os.path.join(oldpath, filename), - os.path.join(newpath, filename) - ) - - def rename(self, oldfilename, newfilename, path=None): - return NotImplemented