Unindex feeds that add a <feed-for>
[0mirror.git] / support.py
blob2feadca73aab59484929c4ce724a8667cb1d55c1
1 # Copyright (C) 2010, Thomas Leonard
2 # See the COPYING file for details, or visit http://0install.net.
4 import os, time
5 from zeroinstall import SafeException
7 def escape_slashes(path):
8 return path.replace('/', '#')
10 def ensure_dirs(path):
11 if not os.path.isdir(path):
12 os.makedirs(path)
13 return path
15 def format_date(date):
16 return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(date))
18 def get_feed_dir(feed):
19 if '#' in feed:
20 raise SafeException("Invalid URL '%s'" % feed)
21 scheme, rest = feed.split('://', 1)
22 domain, rest = rest.split('/', 1)
23 assert scheme in ('http', 'https', 'ftp') # Just to check for mal-formed lines; add more as needed
24 for x in [scheme, domain, rest]:
25 if not x or x.startswith('.'):
26 raise SafeException("Invalid URL '%s'" % feed)
27 return os.path.join('feeds', scheme, domain, escape_slashes(rest))