def fetch_js():
libs = {
'd3.v3.min.js': 'https://d3js.org/d3.v3.min.js',
'd3.v4.min.js': 'https://d3js.org/d3.v4.min.js',
'svg-crowbar.js': 'https://nytimes.github.io/svg-crowbar/svg-crowbar.js',
}
for js, url in libs.iteritems():
target = os.path.sep.join(('LemonGraph', 'data', js))
source = os.path.sep.join(('deps', 'js', js))
dotsource = os.path.sep.join(('deps', 'js', '.%s' % js))
try:
os.mkdir(os.path.sep.join(('deps', 'js')))
except OSError:
pass
try:
s1 = os.stat(source)
except OSError:
with open(dotsource, 'wb') as fh:
for chunk in do_curl(url):
fh.write(chunk)
s1 = os.fstat(fh.fileno())
fh.close()
os.link(dotsource, source)
os.unlink(dotsource)
try:
s2 = os.stat(target)
except OSError:
print >> sys.stderr, "Hard linking: %s -> %s" % (source, target)
os.link(source, target)
continue
for i in (stat.ST_INO, stat.ST_DEV):
if s1[i] != s2[i]:
os.unlink(target)
print >> sys.stderr, "Hard linking: %s -> %s" % (source, target)
os.link(source, target)
break
评论列表
文章目录