File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os .path , sys , time , urllib
2
+ from time import strftime
3
+ import logging
4
+
5
+ __author__ = 'rhoerbe'
6
+
7
+ logger = logging .getLogger (__name__ )
8
+
9
+ def fetch_metadata (url , path , maxage = 600 ):
10
+ """
11
+ :param url: metadata remote location
12
+ :param path: metdata file name
13
+ :param maxage: if max age of existing metadata file (s) is exceeded,
14
+ the file will be fetched from the remote location
15
+ """
16
+ fetch = False
17
+ if not os .path .isfile (path ):
18
+ fetch = True
19
+ logger .debug ("metadata file %s not found" % path )
20
+ elif (os .path .getmtime (path ) + maxage ) < time .time ():
21
+ fetch = True
22
+ logger .debug ("metadata file %s from %s is more than %s s old" %
23
+ (path ,
24
+ strftime ("%Y-%m-%d %H:%M:%S" , time .localtime (os .path .getmtime (path ))),
25
+ maxage ))
26
+ else :
27
+ logger .debug ("metadata file %s is less than %s s old" % (path , maxage ))
28
+ if fetch :
29
+ f = urllib .URLopener ()
30
+ try :
31
+ f .retrieve (url , path )
32
+ logger .debug ("downloaded metadata from %s into %s" % (url , path ))
33
+ except :
34
+ logger .debug ("downloaded metadata from %s failed: %s" %
35
+ (url , sys .exc_info ()[0 ]))
36
+
You can’t perform that action at this time.
0 commit comments