def __init__(repo, url=None, code_dir=None, dpath=None, modname=None, pythoncmd=None): # modname might need to be called egg? import utool as ut if url is not None and '.git@' in url: # parse out specific branch repo.default_branch = url.split('@')[-1] url = '@'.join(url.split('@')[:-1]) else: repo.default_branch = None repo.url = url repo._modname = None if modname is None: modname = [] repo._modname_hints = ut.ensure_iterable(modname) repo.dpath = None repo.scripts = {} if pythoncmd is None: import sys pythoncmd = sys.executable repo.pythoncmd = pythoncmd if dpath is None and repo.url is not None and code_dir is not None: dpath = join(code_dir, repo.reponame) if dpath is not None: repo.dpath = util_path.unixpath(dpath)
def __init__(repo, url=None, code_dir=None, dpath=None, modname=None, pythoncmd=None): # modname might need to be called egg? import utool as ut repo.url = url repo._modname = None if modname is None: modname = [] repo._modname_hints = ut.ensure_iterable(modname) repo.dpath = None repo.scripts = {} repo.pythoncmd = pythoncmd if dpath is None and repo.url is not None and code_dir is not None: dpath = join(code_dir, repo.reponame) if dpath is not None: repo.dpath = util_path.unixpath(dpath)
def grab_zipped_url(zipped_url, ensure=True, appname='utool', download_dir=None, force_commonprefix=True, cleanup=False, redownload=False, spoof=False): r""" downloads and unzips the url Args: zipped_url (str): url which must be either a .zip of a .tar.gz file ensure (bool): eager evaluation if True(default = True) appname (str): (default = 'utool') download_dir (str): containing downloading directory force_commonprefix (bool): (default = True) cleanup (bool): (default = False) redownload (bool): (default = False) spoof (bool): (default = False) CommandLine: python -m utool.util_grabdata --exec-grab_zipped_url --show Example: >>> # DISABLE_DOCTEST >>> from utool.util_grabdata import * # NOQA >>> import utool as ut >>> zipped_url = '?' >>> ensure = True >>> appname = 'utool' >>> download_dir = None >>> force_commonprefix = True >>> cleanup = False >>> redownload = False >>> spoof = False >>> result = grab_zipped_url(zipped_url, ensure, appname, download_dir, >>> force_commonprefix, cleanup, redownload, >>> spoof) >>> print(result) Examples: >>> from utool.util_grabdata import * # NOQA >>> zipped_url = 'https://lev.cs.rpi.edu/public/data/testdata.zip' >>> zipped_url = 'http://www.spam.com/eggs/data.zip' """ zipped_url = clean_dropbox_link(zipped_url) zip_fname = split(zipped_url)[1] data_name = split_archive_ext(zip_fname)[0] # Download zipfile to if download_dir is None: download_dir = util_cplat.get_app_resource_dir(appname) # Zipfile should unzip to: data_dir = join(download_dir, data_name) if ensure or redownload: if redownload: util_path.remove_dirs(data_dir) util_path.ensurepath(download_dir) if not exists(data_dir) or redownload: # Download and unzip testdata zip_fpath = realpath(join(download_dir, zip_fname)) #print('[utool] Downloading archive %s' % zip_fpath) if not exists(zip_fpath) or redownload: download_url(zipped_url, zip_fpath, spoof=spoof) unarchive_file(zip_fpath, force_commonprefix) if cleanup: util_path.delete(zip_fpath) # Cleanup if cleanup: util_path.assert_exists(data_dir) return util_path.unixpath(data_dir)