mirror of
https://github.com/frida/frida-python
synced 2026-06-08 14:16:17 +00:00
Look for a local .egg before hitting the network
To speed things up in situations where the network path is expected to fail.
This commit is contained in:
committed by
Ole André Vadla Ravnås
parent
90992cbf39
commit
581111cd07
@@ -66,6 +66,7 @@ class FridaPrebuiltExt(build_ext):
|
||||
os.makedirs(target_dir)
|
||||
except:
|
||||
pass
|
||||
|
||||
if in_source_package:
|
||||
python_version = sys.version_info[0:2]
|
||||
python_major_version = python_version[0]
|
||||
@@ -81,19 +82,25 @@ class FridaPrebuiltExt(build_ext):
|
||||
os_version = "linux-x86_64" if arch == 64 else "linux-i686"
|
||||
else:
|
||||
os_version = "linux-" + machine
|
||||
else:
|
||||
raise NotImplementedError("unsupported OS")
|
||||
|
||||
network_error = None
|
||||
egg_path = os.path.expanduser(
|
||||
"~/frida-{}-py{}.{}-{}.egg".format(frida_version, python_version[0], python_version[1], os_version))
|
||||
print("looking for prebuilt extension in home directory, i.e.", egg_path)
|
||||
|
||||
try:
|
||||
with open(egg_path, "rb") as cache:
|
||||
egg_data = cache.read()
|
||||
except IOError as e:
|
||||
print("prebuild extension not found in home directory, will try downloading it")
|
||||
|
||||
print("querying pypi for available prebuilds")
|
||||
client = xmlrpclib.ServerProxy("https://pypi.python.org/pypi", transport=UrllibTransport())
|
||||
urls = client.release_urls("frida", frida_version)
|
||||
|
||||
urls = [url for url in urls if url['python_version'] != 'source']
|
||||
|
||||
def parse_version(version):
|
||||
return tuple(map(int, version.split(".")))
|
||||
|
||||
if python_major_version >= 3:
|
||||
urls = [url for url in urls if parse_version(url['python_version'])[0] == python_major_version]
|
||||
else:
|
||||
@@ -103,34 +110,20 @@ class FridaPrebuiltExt(build_ext):
|
||||
urls = [url for url in urls if url['filename'].endswith(os_suffix)]
|
||||
|
||||
if len(urls) == 0:
|
||||
raise Exception("Could not find prebuilt Frida extension. "
|
||||
"Prebuilds only provided for Python 2.7 and 3.4+.")
|
||||
raise NotImplementedError("could not find prebuilt Frida extension; "
|
||||
"prebuilds only provided for Python 2.7 and 3.4+")
|
||||
|
||||
url = urls[0]
|
||||
egg_filename = url['filename']
|
||||
egg_url = url['url']
|
||||
|
||||
print("downloading prebuilt extension from", egg_url)
|
||||
timeout = 120 # We'll assume the user has at least 200 kB/s transfer speed.
|
||||
egg_data = urlopen(egg_url, timeout=timeout).read()
|
||||
except Exception as e:
|
||||
network_error = e
|
||||
|
||||
if network_error is not None:
|
||||
print("network query failed")
|
||||
|
||||
egg_path = os.path.expanduser(
|
||||
"~/frida-{}-py{}.{}-{}.egg".format(frida_version, python_version[0], python_version[1], os_version))
|
||||
print("looking for prebuilt extension in home directory, i.e.", egg_path)
|
||||
try:
|
||||
with open(egg_path, "rb") as f:
|
||||
egg_data = f.read()
|
||||
except:
|
||||
print("no prebuilt extension found in home directory")
|
||||
egg_data = None
|
||||
|
||||
if egg_data is None:
|
||||
raise network_error
|
||||
print("downloading prebuilt extension from", egg_url)
|
||||
timeout = 120 # We'll assume the user has at least 200 kB/s transfer speed.
|
||||
egg_data = urlopen(egg_url, timeout=timeout).read()
|
||||
except Exception as e:
|
||||
message = "unable to download it within 120 seconds; please download it manually to {}"
|
||||
print(message.format(egg_path))
|
||||
raise e
|
||||
|
||||
egg_file = BytesIO(egg_data)
|
||||
|
||||
@@ -147,6 +140,10 @@ class FridaPrebuiltExt(build_ext):
|
||||
shutil.copyfile(frida_extension, target)
|
||||
|
||||
|
||||
def parse_version(version):
|
||||
return tuple(map(int, version.split(".")))
|
||||
|
||||
|
||||
setup(
|
||||
name="frida",
|
||||
version=frida_version,
|
||||
|
||||
Reference in New Issue
Block a user