1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 #
18 # (c) 2008 by Alexander Schier
19
20
21 import popen2, os
22
23 lang="c"
24 if os.environ.has_key("LANG"):
25 lang=os.environ['LANG'].lower().split("_")[0]
26
27 strings={
28 "de":
29 {
30 'Please choose the device, on which the files should be sorted.':
31 'Waehlen Sie das Gerät auf dem die Dateien sortiert werden sollen.',
32 'Device':
33 'Gerät',
34 'Size':
35 'Größe',
36 'files sucessfully sorted.':
37 'Dateien erfolgreich sortiert.',
38 'error while sorting the files!':
39 'Fehler beim Sortieren der Dateien!',
40 },
41 }
42
43 def _(string):
44 if strings.has_key(lang) and strings[lang].has_key(string):
45 return strings[lang][string]
46 else:
47 return string
48
49 def formatSize(size):
50 size=float(size)
51 if size > 1024*1024*1024:
52 return "%.3f GB" % (size/(1024*1024*1024.0))
53 elif size > 1024*1024:
54 return "%.3f MB"%(size/(1024*1024.0))
55 else:
56 return "%d Byte"%size
57
58 outin=popen2.popen2("hal-device")
59 data=outin[0].read()
60
61 devices=data.split("\n\n")
62 fatdevices=[]
63 for device in devices:
64 if "volume.fstype = 'vfat'" in device:
65 label=""
66 dev=""
67 mounted=True
68 size=0
69 for line in device.split("\n"):
70 tmp=line.split("=", 1)
71 if(tmp[0].strip()=="block.device"):
72 dev=tmp[1].strip().split("'")[1] #i.e. " '/dev/sdb1' (string)"
73 elif tmp[0].strip()=="volume.label":
74 label=tmp[1].strip().split("'")[1]
75 elif tmp[0].strip()=="volume.is_mounted":
76 mounted=(tmp[1].strip().split(" ")[0]!="false")
77 elif tmp[0].strip()=="volume.size":
78 size=tmp[1].strip().split(" ")[0]
79 if dev!="":
80 fatdevices.append((dev, label, formatSize(size), mounted))
81 options='--list --text "'+_('Please choose the device, on which the files should be sorted.')+'" --column="'+_('Device')+'" --column="'+_('Label')+'" --column="'+_("Size")+'"'
82 for fatdevice in fatdevices:
83 if not fatdevice[3]:
84 options+=' "%s" "%s" "%s"'%(fatdevice[0], fatdevice[1], fatdevice[2])
85 tmp=popen2.popen2("zenity %s"%options)
86 device=tmp[0].read().strip()
87 if device!="":
88 if(os.system('fatsort "%s"'%device)==0):
89 os.system('zenity --info --text="'+_('files sucessfully sorted.')+'"')
90 else:
91 os.system('zenity --error --text="'+_('error while sorting the files!')+'"')