-
Notifications
You must be signed in to change notification settings - Fork 0
/
diskfree.py
109 lines (96 loc) · 3.49 KB
/
diskfree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
from xbmcgui import Window, WindowDialog
import xbmc, xbmcgui
import xbmcaddon
#python modules
import os, time, stat, re, copy
import statvfs
__author__ = "Senufo"
__scriptid__ = "service.diskfree"
__scriptname__ = "diskfree"
Addon = xbmcaddon.Addon(__scriptid__)
__cwd__ = Addon.getAddonInfo('path')
__version__ = Addon.getAddonInfo('version')
__language__ = Addon.getLocalizedString
__profile__ = xbmc.translatePath(Addon.getAddonInfo('profile'))
__resource__ = xbmc.translatePath(os.path.join(__cwd__, 'resources',
'lib'))
DEBUG_LOG = True
#Function Debug
def debug(msg):
"""
print message if DEBUG_LOG == True
"""
if DEBUG_LOG == True: print " [%s] : %s " % (__scriptid__, msg)
#Position du texte
x = int(Addon.getSetting('x'))
y = int(Addon.getSetting('y'))
width = int(Addon.getSetting('width'))
height = int(Addon.getSetting('height'))
font = Addon.getSetting('font')
color = Addon.getSetting('color')
#ID de la fenetre HOME
WINDOW_HOME = 10000
#Variable pour statvfs
F_BSIZE = 0 # Preferred file system block size
F_FRSIZE = 1 # Fundamental file system block size
F_BLOCKS = 2 # Total number of file system blocks (FRSIZE)
F_BFREE = 3 # Total number of free blocks
F_BAVAIL = 4 # Free blocks available to non-superuser
F_FILES = 5 # Total number of file nodes
F_FFREE = 6 # Total number of free file nodes
F_FAVAIL = 7 # Free nodes available to non-superuser
F_FLAG = 8 # Flags (see your local statvfs man page)
F_NAMEMAX = 9 # Maximum file name length
#sys.path.append (__resource__)
def freespace_disk(path):
"""
freespace(path) -> integer
Return the number of bytes available to the user on the file system
pointed to by path.
"""
try:
s = os.statvfs(path)
return s[F_BAVAIL] * long(s[F_BSIZE])
except OSError, why:
print('"%r: %s' % (path, why), DWARNING)
return 0
def totalspace_disk(path):
"""
totalspace(path) -> integer
Return the number of total bytes available on the file system
pointed to by path.
"""
try:
s = os.statvfs(path)
return s[F_BLOCKS] * long(s[F_BSIZE])
except OSError, why:
print('"%r: %s' % (path, why), DWARNING)
return 0
ImgBoxDisk = None
ImgBoxDisk = None
filename = xbmc.translatePath("special://profile/addon_data/service.diskfree/diskfree.png")
#filename = 'special://home/henri/.xbmc/scripts/test.png'
ImgBoxDiskId = None
ImgBoxDiskId = None
#start_time = time.time()
start_time = 0
re_added_control = False
#Recupère les arguments envoyés par le skin qui a lancé le script
for arg in sys.argv:
param = str(arg).lower()
debug("param = %s " % param)
if 'disk=' in param:
disk = param.replace('disk=', '')
#On récupère l'ID de la fenêtre de skin qui à lancer le script
okno = Window(xbmcgui.getCurrentWindowId())
#On recupere les parametres des disques
#time = time.time()
freespace = freespace_disk('/home/')
totalspace = totalspace_disk('/home')
diskfree = ('%iGB') % (((freespace / 1024) / 1024) / 1024)
freespace = (((freespace / 1024) / 1024) / 1024)
totalspace = (((totalspace / 1024) / 1024) / 1024)
percent = totalspace and (totalspace - freespace) * 1.0 / totalspace or 0.0
debug( "f = %s, t = %s Pou = %s " % (freespace,totalspace,percent))
okno.setProperty('DISK' , '%s Go' % freespace )