mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-07 13:46:38 +02:00
Move function to start of python file to make it more idiomatic
This commit is contained in:
parent
b3cb2690f3
commit
0cfa598e63
@ -10,6 +10,19 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
import os
|
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:
|
with urllib.request.urlopen('https://api.hishtory.dev/api/v1/download') as response:
|
||||||
resp_body = response.read()
|
resp_body = response.read()
|
||||||
download_options = json.loads(resp_body)
|
download_options = json.loads(resp_body)
|
||||||
@ -31,19 +44,6 @@ else:
|
|||||||
with urllib.request.urlopen(download_url) as response:
|
with urllib.request.urlopen(download_url) as response:
|
||||||
hishtory_binary = response.read()
|
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')
|
tmpFilePath = os.path.join(get_executable_tmpdir(), 'hishtory-client')
|
||||||
if os.path.exists(tmpFilePath):
|
if os.path.exists(tmpFilePath):
|
||||||
os.remove(tmpFilePath)
|
os.remove(tmpFilePath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user