Ejemplo n.º 1
0
def download(grib2_dir=None):
    """
    Download grib2 files

    Args:
        grib2_dir - grib2 data directory, if omitted, the current directory is used
    """
    import os

    grib2.verbose = verbose
    grib2_dir = grib2_dir if grib2_dir else os.path.abspath(os.path.dirname(__file__)) # use current dir if none provided
    grib2.download(grib2_dir)
Ejemplo n.º 2
0
def download(grib2_dir=None):
    """
    Download grib2 files

    Args:
        grib2_dir - grib2 data directory, if omitted, the current directory is used
    """
    import os

    grib2.verbose = verbose
    grib2_dir = grib2_dir if grib2_dir else os.path.abspath(
        os.path.dirname(__file__))  # use current dir if none provided
    grib2.download(grib2_dir)
Ejemplo n.º 3
0
def update_cache():
	new_download_dir = get_new_download_dir()
	lock_acquired = downloading_mutex.acquire(False)

	if not lock_acquired:
		print "Service Unavailable"
		abort(503) # Service Unavailable

	try:
		new_files = grib2.download(download_dir, new_download_dir)
		if new_files:
			old_download_dir = os.path.realpath(download_dir)
			with mutex:
				if os.path.exists(download_dir) and os.path.islink(download_dir):
					os.unlink(download_dir)
				elif os.path.exists(download_dir) and os.path.isdir(download_dir):
					shutil.rmtree(download_dir)
				os.symlink(new_download_dir, download_dir)
			if os.path.exists(old_download_dir) and not os.path.islink(old_download_dir):
				shutil.rmtree(old_download_dir)

		downloading_mutex.release()
	except:
		downloading_mutex.release()
		abort(500)

	if new_files:
		return ('Success - new files downloaded.', 200)
	else:
		return ('Success - no update needed.', 304)