mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-12 14:13:38 +00:00
Merge pull request #1035 from JackDandy/feature/AddFreeSpace
Add free space stat (if obtainable) of parent folder(s) to footer.
This commit is contained in:
commit
7db1743adf
3 changed files with 88 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
[develop changelog]
|
[develop changelog]
|
||||||
|
|
||||||
* Fix Events shutdown (a manual start-up is required after updating to this fix)
|
* Fix Events shutdown (a manual start-up is required after updating to this fix)
|
||||||
|
* Add free space stat (if obtainable) of parent folder(s) to footer
|
||||||
|
|
||||||
|
|
||||||
### 0.13.10 (2018-01-08 17:20:00 UTC)
|
### 0.13.10 (2018-01-08 17:20:00 UTC)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#import re
|
#import re
|
||||||
#from sickbeard import db, sbdatetime
|
#from sickbeard import db, sbdatetime
|
||||||
#from sickbeard.common import *
|
#from sickbeard.common import *
|
||||||
|
#from sickbeard.helpers import df
|
||||||
<% def sg_var(varname, default=False): return getattr(sickbeard, varname, default) %>#slurp#
|
<% def sg_var(varname, default=False): return getattr(sickbeard, varname, default) %>#slurp#
|
||||||
<% def sg_str(varname, default=''): return getattr(sickbeard, varname, default) %>#slurp#
|
<% def sg_str(varname, default=''): return getattr(sickbeard, varname, default) %>#slurp#
|
||||||
##
|
##
|
||||||
|
@ -61,7 +62,14 @@ try:
|
||||||
recent_search_timeleft = str(sickbeard.recentSearchScheduler.timeLeft()).split('.')[0]
|
recent_search_timeleft = str(sickbeard.recentSearchScheduler.timeLeft()).split('.')[0]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
recent_search_timeleft = 'soon'
|
recent_search_timeleft = 'soon'
|
||||||
|
diskfree, min_output = df()
|
||||||
|
if min_output:
|
||||||
|
avail = ', '.join(['%s <span class="footerhighlight">%s</span>' % (drive, free) for (drive, free) in diskfree])
|
||||||
%>
|
%>
|
||||||
|
<style>
|
||||||
|
.stat-table{margin:0 auto}
|
||||||
|
.stat-table > tbody > tr > td{padding:0 5px}
|
||||||
|
</style>
|
||||||
##
|
##
|
||||||
<span class="footerhighlight">$shows_total</span> shows (<span class="footerhighlight">$shows_active</span> active)
|
<span class="footerhighlight">$shows_total</span> shows (<span class="footerhighlight">$shows_active</span> active)
|
||||||
| <span class="footerhighlight">$ep_downloaded</span><%=
|
| <span class="footerhighlight">$ep_downloaded</span><%=
|
||||||
|
@ -74,6 +82,26 @@ except AttributeError:
|
||||||
%> / <span class="footerhighlight">$ep_total</span> episodes downloaded $ep_percentage
|
%> / <span class="footerhighlight">$ep_total</span> episodes downloaded $ep_percentage
|
||||||
| recent search: <span class="footerhighlight">$recent_search_timeleft</span>
|
| recent search: <span class="footerhighlight">$recent_search_timeleft</span>
|
||||||
| backlog search: <span class="footerhighlight">$next_backlog_timeleft</span>
|
| backlog search: <span class="footerhighlight">$next_backlog_timeleft</span>
|
||||||
|
#if diskfree
|
||||||
|
#if min_output
|
||||||
|
<br>free space $avail
|
||||||
|
#else
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="stat-table" cellspacing="5" cellpadding="5">
|
||||||
|
<caption style="display:none">Free space stats for volume/path</caption>
|
||||||
|
<tbody>
|
||||||
|
#for i, drive in enumerate(diskfree)
|
||||||
|
<tr>
|
||||||
|
<td>#if not i#free space#end if#</td>
|
||||||
|
<td><span class="footerhighlight">$drive[1]</span></td>
|
||||||
|
<td style="text-align:left">$drive[0]</td>
|
||||||
|
</tr>
|
||||||
|
#end for
|
||||||
|
</tobdy>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
#end if
|
||||||
|
#end if
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1555,3 +1555,62 @@ def datetime_to_epoch(dt):
|
||||||
dt = dt.replace(tzinfo=sb_timezone)
|
dt = dt.replace(tzinfo=sb_timezone)
|
||||||
utc_naive = dt.replace(tzinfo=None) - dt.utcoffset()
|
utc_naive = dt.replace(tzinfo=None) - dt.utcoffset()
|
||||||
return int((utc_naive - datetime.datetime(1970, 1, 1)).total_seconds())
|
return int((utc_naive - datetime.datetime(1970, 1, 1)).total_seconds())
|
||||||
|
|
||||||
|
|
||||||
|
def df():
|
||||||
|
"""
|
||||||
|
Return disk free space at known parent locations
|
||||||
|
|
||||||
|
:return: string path, string value that is formatted size
|
||||||
|
:rtype: list of tuples
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
min_output = True
|
||||||
|
if sickbeard.ROOT_DIRS:
|
||||||
|
targets = []
|
||||||
|
for path in sickbeard.ROOT_DIRS.split('|')[1:]:
|
||||||
|
location_parts = os.path.splitdrive(path)
|
||||||
|
target = location_parts[0]
|
||||||
|
if 'win32' == sys.platform:
|
||||||
|
if not re.match('(?i)[a-z]:(?:\\\\)?$', target):
|
||||||
|
# simple drive letter not found, fallback to full path
|
||||||
|
target = path
|
||||||
|
min_output = False
|
||||||
|
elif sys.platform.startswith(('linux', 'darwin', 'sunos5')) or 'bsd' in sys.platform:
|
||||||
|
target = path
|
||||||
|
min_output = False
|
||||||
|
if target and target not in targets:
|
||||||
|
targets += [target]
|
||||||
|
free = freespace(path)
|
||||||
|
if None is not free:
|
||||||
|
result += [(target, sizeof_fmt(free).replace(' ', ''))]
|
||||||
|
return result, min_output
|
||||||
|
|
||||||
|
|
||||||
|
def freespace(path=None):
|
||||||
|
"""
|
||||||
|
Return free space available at path location
|
||||||
|
|
||||||
|
:param path: Example paths (Windows) = '\\\\192.168.0.1\\sharename\\existing_path', 'd:\\existing_path'
|
||||||
|
Untested with mount points under linux
|
||||||
|
:type path: basestring
|
||||||
|
:return: Size in bytes
|
||||||
|
:rtype: long
|
||||||
|
"""
|
||||||
|
result = None
|
||||||
|
|
||||||
|
if 'win32' == sys.platform:
|
||||||
|
try:
|
||||||
|
import ctypes
|
||||||
|
if None is not ctypes:
|
||||||
|
max_val = (2 ** 64) - 1
|
||||||
|
storage = ctypes.c_ulonglong(max_val)
|
||||||
|
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(path), None, None, ctypes.pointer(storage))
|
||||||
|
result = (storage.value, None)[max_val == storage.value]
|
||||||
|
except(StandardError, Exception):
|
||||||
|
pass
|
||||||
|
elif sys.platform.startswith(('linux', 'darwin', 'sunos5')) or 'bsd' in sys.platform:
|
||||||
|
storage = os.statvfs(path)
|
||||||
|
result = storage.f_bavail * storage.f_frsize
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
Loading…
Reference in a new issue