airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-1167] Support microseconds in FTPHook modification time
Date Fri, 05 May 2017 07:17:49 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 379115f84 -> 4284e6485


[AIRFLOW-1167] Support microseconds in FTPHook modification time

Closes #2268 from NielsZeilemaker/fix-ftp-hook


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/4284e648
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/4284e648
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/4284e648

Branch: refs/heads/master
Commit: 4284e6485f4e80522b675014c0e4c48d2fe53f8a
Parents: 379115f
Author: Niels Zeilemaker <nielszeilemaker@godatadriven.com>
Authored: Fri May 5 09:17:40 2017 +0200
Committer: Bolke de Bruin <bolke@xs4all.nl>
Committed: Fri May 5 09:17:40 2017 +0200

----------------------------------------------------------------------
 airflow/contrib/hooks/ftp_hook.py    |  7 ++++++-
 tests/contrib/hooks/test_ftp_hook.py | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/4284e648/airflow/contrib/hooks/ftp_hook.py
----------------------------------------------------------------------
diff --git a/airflow/contrib/hooks/ftp_hook.py b/airflow/contrib/hooks/ftp_hook.py
index 9e12c59..148811f 100644
--- a/airflow/contrib/hooks/ftp_hook.py
+++ b/airflow/contrib/hooks/ftp_hook.py
@@ -226,7 +226,12 @@ class FTPHook(BaseHook):
     def get_mod_time(self, path):
         conn = self.get_conn()
         ftp_mdtm = conn.sendcmd('MDTM ' + path)
-        return datetime.datetime.strptime(ftp_mdtm[4:], '%Y%m%d%H%M%S')
+        time_val = ftp_mdtm[4:]
+        # time_val optionally has microseconds
+        try:
+            return datetime.datetime.strptime(time_val, "%Y%m%d%H%M%S.%f")
+        except ValueError:
+            return datetime.datetime.strptime(time_val, '%Y%m%d%H%M%S')
 
 
 class FTPSHook(FTPHook):

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/4284e648/tests/contrib/hooks/test_ftp_hook.py
----------------------------------------------------------------------
diff --git a/tests/contrib/hooks/test_ftp_hook.py b/tests/contrib/hooks/test_ftp_hook.py
index ab6f459..c81593d 100644
--- a/tests/contrib/hooks/test_ftp_hook.py
+++ b/tests/contrib/hooks/test_ftp_hook.py
@@ -77,6 +77,24 @@ class TestFTPHook(unittest.TestCase):
 
         self.conn_mock.rename.assert_called_once_with(from_path, to_path)
         self.conn_mock.quit.assert_called_once_with()
+        
+    def test_mod_time(self):
+        self.conn_mock.sendcmd.return_value = '213 20170428010138'
+        
+        path = '/path/file'
+        with fh.FTPHook() as ftp_hook:
+            ftp_hook.get_mod_time(path)
+
+        self.conn_mock.sendcmd.assert_called_once_with('MDTM ' + path)
+        
+    def test_mod_time_micro(self):
+        self.conn_mock.sendcmd.return_value = '213 20170428010138.003'
+        
+        path = '/path/file'
+        with fh.FTPHook() as ftp_hook:
+            ftp_hook.get_mod_time(path)
+
+        self.conn_mock.sendcmd.assert_called_once_with('MDTM ' + path)
 
 
 if __name__ == '__main__':


Mime
View raw message