コード例 #1
0
ファイル: model_store.py プロジェクト: yangyuren03/rsna-2019
def get_model_file(name, root=os.path.join('~', '.encoding', 'models')):
    r"""Return location for the pretrained on local file system.

    This function will download from online model zoo when model cannot be found or has mismatch.
    The root directory will be created if it doesn't exist.

    Parameters
    ----------
    name : str
        Name of the model.
    root : str, default '~/.encoding/models'
        Location for keeping the model parameters.

    Returns
    -------
    file_path
        Path to the requested pretrained model file.
    """
    file_name = '{name}-{short_hash}'.format(name=name,
                                             short_hash=short_hash(name))
    root = os.path.expanduser(root)
    file_path = os.path.join(root, file_name + '.pth')
    sha1_hash = _model_sha1[name]
    if os.path.exists(file_path):
        if check_sha1(file_path, sha1_hash):
            return file_path
        else:
            print('Mismatch in the content of model file {} detected.' +
                  ' Downloading again.'.format(file_path))
    else:
        print('Model file {} is not found. Downloading.'.format(file_path))

    if not os.path.exists(root):
        os.makedirs(root)

    zip_file_path = os.path.join(root, file_name + '.zip')
    repo_url = os.environ.get('ENCODING_REPO', encoding_repo_url)
    if repo_url[-1] != '/':
        repo_url = repo_url + '/'
    download(_url_format.format(repo_url=repo_url, file_name=file_name),
             path=zip_file_path,
             overwrite=True)
    with zipfile.ZipFile(zip_file_path) as zf:
        zf.extractall(root)
    os.remove(zip_file_path)

    if check_sha1(file_path, sha1_hash):
        return file_path
    else:
        raise ValueError(
            'Downloaded file has different hash. Please try again.')
コード例 #2
0
ファイル: crawrer.py プロジェクト: tayduivn/android-2
def main():
    if len(sys.argv) <= 1:
        print "Please Set Argv Resource Path"
        return

    resourcePath = sys.argv[1]
    absResourcePath = os.path.abspath(resourcePath)
    sid = session.getSessionId()
    downloadFilePath = files.getDownloadPath(sid)
    zipFile = files.download(sid, downloadFilePath)
    files.unarchive(zipFile, absResourcePath)
    files.delete(zipFile)
コード例 #3
0
def get_modules(omm_ip):
    try:
        files.download(ip=omm_ip,
                       filename='module_registry.xml',
                       remotepath='/opt/sts/omm/')
        print('DOWNLOADED SUCCESSFULLY')
    except Exception as e:
        print('"downloading module_registry.xml from OMM" FAILED')
        print(e)
    with open("module_registry.xml") as xml_file:
        data_dict = xmltodict.parse(xml_file.read())
        xml_file.close()
        data = json.loads(
            json.dumps(data_dict['ModuleRegistry']['Modules']['BUS']))
        data_json = json.dumps(data_dict['ModuleRegistry']['Modules']['BUS'])
        with open("data.json", "w") as json_file:
            json_file.write(data_json)
            json_file.close()
    pprint(data)
    print('DATATYPE:' + str(type(data)))
    return data
コード例 #4
0
def handle_post_fetch(link):
    print(f'Handling post fetch', link.url)
    base_url = get_base_url(link.url)

    try:
        download(link.html, base_url, get_path(link.url), TARGET_DIR)
    except Exception as e:
        raise Exception("Failed to download site %r", e)

    try:

        for url in link.html.links:
            sanitised_url = sanitise_url(url)
            if get_base_url(sanitised_url) not in {'', base_url}: continue

            parsed = urlparse(sanitised_url)
            if not parsed.netloc:
                assert parsed.scheme == ''
                sanitised_url = urljoin(base_url, sanitised_url)

            print(f'Adding {sanitised_url} to queue')
            q.put(Link(sanitised_url, link.depth + 1))
    except Exception as e:
        raise Exception("Handling post fetch failed %r", e)
コード例 #5
0
        elif args.delete_id:
            users.delete_id(args.delete_id)

        elif args.upload:
            if args.dest_id:
                files.upload(args.upload, args.dest_id)
            else:
                print("--upload necesita --dest_id")

        elif args.list_files:
            files.list_files()

        elif args.download:
            if args.source_id:
                files.download(args.download, args.source_id)
            else:
                print("--download necesita --source_id")

        elif args.delete_file:
            files.delete(args.delete_file)

        # Para encriptar pedimos la clave publica del destinatario, ciframos
        # y guardamos el fichero encriptado en path_archivos
        elif args.encrypt:
            if args.dest_id:
                publicKey = users.get_public_key(args.dest_id)
                if publicKey is not None:
                    try:
                        f = open(args.encrypt, "rb")
                        mensaje_cifrado = crypto.encrypt(f.read(), publicKey)
コード例 #6
0
ファイル: tests.py プロジェクト: sumloli/Migration
try:
    remove = rest.make_request('DELETE',
                               main.mms,
                               f'/cm/profiles/{id}',
                               params={'roleuser': '******'})
    print(remove)
    print('SUCCESS')
except Exception as e:
    print('"DELETE profile" FAILED')
    print(e)

print('\nDEBUG FUNCTION:')
print('DEBUG FUNCTION "downloading file":')
try:
    files.download(ip='10.240.151.112',
                   filename='tts.pcap',
                   remotepath='/opt/sts/')
    print('SUCCESS')
except Exception as e:
    print('"downloading file" FAILED')
    print(e)
print('\nDEBUG FUNCTION:')
print('DEBUG FUNCTION "downloading module_registry.xml from OMM":')
try:
    # download(ip='10.97.155.51', filename='module_registry.xml', remotepath='/opt/sts/omm/')
    files.download(ip='10.240.206.111',
                   filename='module_registry.xml',
                   remotepath='/opt/sts/omm/')
    print('SUCCESS')
except Exception as e:
    print('"downloading module_registry.xml from OMM" FAILED')
コード例 #7
0
ファイル: app.py プロジェクト: hy57in/Helmet-Detection
def download_process():
    global g_filename, g_result

    img = download(g_filename)

    return jsonify({'Result': g_result, "imgSrc": img}), 200