Move function to start of python file to make it more idiomatic

This commit is contained in:
David Dworken 2024-02-09 20:21:27 -08:00
parent b3cb2690f3
commit 0cfa598e63
No known key found for this signature in database

View File

@ -10,6 +10,19 @@ import platform
import sys
import os
def get_executable_tmpdir():
specified_dir = os.environ.get('TMPDIR', '')
if specified_dir:
return specified_dir
try:
if hasattr(os, 'ST_NOEXEC'):
if os.statvfs("/tmp").f_flag & os.ST_NOEXEC:
# /tmp/ is mounted as NOEXEC, so fall back to the current working directory
return os.getcwd()
except:
pass
return "/tmp/"
with urllib.request.urlopen('https://api.hishtory.dev/api/v1/download') as response:
resp_body = response.read()
download_options = json.loads(resp_body)
@ -31,19 +44,6 @@ else:
with urllib.request.urlopen(download_url) as response:
hishtory_binary = response.read()
def get_executable_tmpdir():
specified_dir = os.environ.get('TMPDIR', '')
if specified_dir:
return specified_dir
try:
if hasattr(os, 'ST_NOEXEC'):
if os.statvfs("/tmp").f_flag & os.ST_NOEXEC:
# /tmp/ is mounted as NOEXEC, so fall back to the current working directory
return os.getcwd()
except:
pass
return "/tmp/"
tmpFilePath = os.path.join(get_executable_tmpdir(), 'hishtory-client')
if os.path.exists(tmpFilePath):
os.remove(tmpFilePath)