2019-01-09 22:59:03 +00:00
|
|
|
from . import HydrusConstants as HC
|
|
|
|
from . import HydrusData
|
|
|
|
from . import HydrusGlobals as HG
|
|
|
|
from . import HydrusPaths
|
2018-05-23 21:05:06 +00:00
|
|
|
import os
|
2018-05-09 20:23:00 +00:00
|
|
|
import webbrowser
|
|
|
|
|
2018-06-06 21:27:02 +00:00
|
|
|
def DeletePath( path, always_delete_fully = False ):
|
2018-05-16 20:09:50 +00:00
|
|
|
|
2018-06-06 21:27:02 +00:00
|
|
|
if HC.options[ 'delete_to_recycle_bin' ] == True and not always_delete_fully:
|
2018-05-16 20:09:50 +00:00
|
|
|
|
|
|
|
HydrusPaths.RecyclePath( path )
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
HydrusPaths.DeletePath( path )
|
|
|
|
|
|
|
|
|
2018-05-09 20:23:00 +00:00
|
|
|
def GetCurrentTempDir():
|
|
|
|
|
2018-05-23 21:05:06 +00:00
|
|
|
temp_path_override = GetTempPathOverride()
|
2018-05-09 20:23:00 +00:00
|
|
|
|
|
|
|
if temp_path_override is None:
|
|
|
|
|
|
|
|
return HydrusPaths.tempfile.gettempdir()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return temp_path_override
|
|
|
|
|
|
|
|
|
|
|
|
def GetTempDir():
|
|
|
|
|
2018-05-23 21:05:06 +00:00
|
|
|
temp_path_override = GetTempPathOverride()
|
2018-05-09 20:23:00 +00:00
|
|
|
|
|
|
|
return HydrusPaths.GetTempDir( dir = temp_path_override ) # none means default
|
|
|
|
|
|
|
|
def GetTempPath( suffix = '' ):
|
|
|
|
|
2018-05-23 21:05:06 +00:00
|
|
|
temp_path_override = GetTempPathOverride()
|
2018-05-09 20:23:00 +00:00
|
|
|
|
|
|
|
return HydrusPaths.GetTempPath( suffix = suffix, dir = temp_path_override )
|
|
|
|
|
|
|
|
def LaunchPathInWebBrowser( path ):
|
|
|
|
|
|
|
|
LaunchURLInWebBrowser( 'file:///' + path )
|
|
|
|
|
|
|
|
def LaunchURLInWebBrowser( url ):
|
|
|
|
|
|
|
|
web_browser_path = HG.client_controller.new_options.GetNoneableString( 'web_browser_path' )
|
|
|
|
|
|
|
|
if web_browser_path is None:
|
|
|
|
|
|
|
|
webbrowser.open( url )
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
HydrusPaths.LaunchFile( url, launch_path = web_browser_path )
|
|
|
|
|
|
|
|
|
2018-05-23 21:05:06 +00:00
|
|
|
def GetTempPathOverride():
|
|
|
|
|
|
|
|
temp_path_override = HG.client_controller.new_options.GetNoneableString( 'temp_path_override' )
|
|
|
|
|
|
|
|
if temp_path_override is not None and not os.path.exists( temp_path_override ):
|
|
|
|
|
|
|
|
HydrusData.ShowText( 'The temp path ' + temp_path_override + ' does not exist! Please either create it or change the option!' )
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
return temp_path_override
|
|
|
|
|