ubuntuusers.de

Anhang: fatsort-gui.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# (c) 2008 by Alexander Schier


import popen2, os

lang="c"
if os.environ.has_key("LANG"):
	lang=os.environ['LANG'].lower().split("_")[0]

strings={
"de": 
	{
	'Please choose the device, on which the files should be sorted.':
		'Waehlen Sie das Gerät auf dem die Dateien sortiert werden sollen.',
	'Device':
		'Gerät',
	'Size':
		'Größe',
	'files sucessfully sorted.':
		'Dateien erfolgreich sortiert.',
	'error while sorting the files!':
		'Fehler beim Sortieren der Dateien!',
	},
}

def _(string):
	if strings.has_key(lang) and strings[lang].has_key(string):
		return strings[lang][string]
	else:
		return string

def formatSize(size):
	size=float(size)
	if size > 1024*1024*1024:
		return "%.3f GB" % (size/(1024*1024*1024.0))
	elif size > 1024*1024:
		return "%.3f MB"%(size/(1024*1024.0))
	else:
		return "%d Byte"%size

outin=popen2.popen2("hal-device")
data=outin[0].read()

devices=data.split("\n\n")
fatdevices=[]
for device in devices:
	if "volume.fstype = 'vfat'" in device:
		label=""
		dev=""
		mounted=True
		size=0
		for line in device.split("\n"):
			tmp=line.split("=", 1)
			if(tmp[0].strip()=="block.device"):
				dev=tmp[1].strip().split("'")[1] #i.e. " '/dev/sdb1'  (string)"
			elif tmp[0].strip()=="volume.label":
				label=tmp[1].strip().split("'")[1]
			elif tmp[0].strip()=="volume.is_mounted":
				mounted=(tmp[1].strip().split(" ")[0]!="false")
			elif tmp[0].strip()=="volume.size":
				size=tmp[1].strip().split(" ")[0]
		if dev!="":
			fatdevices.append((dev, label, formatSize(size), mounted))
options='--list --text "'+_('Please choose the device, on which the files should be sorted.')+'" --column="'+_('Device')+'" --column="'+_('Label')+'" --column="'+_("Size")+'"'
for fatdevice in fatdevices:
	if not fatdevice[3]:
		options+=' "%s" "%s" "%s"'%(fatdevice[0], fatdevice[1], fatdevice[2])
tmp=popen2.popen2("zenity %s"%options)
device=tmp[0].read().strip()
if device!="":
	if(os.system('fatsort "%s"'%device)==0):
		os.system('zenity --info --text="'+_('files sucessfully sorted.')+'"')
	else:
		os.system('zenity --error --text="'+_('error while sorting the files!')+'"')
Anhang herunterladen

http://blog.laxu.de/2008/02/03/fatsort-gui/

Diese Revision wurde am 30. März 2013 13:49 von march erstellt.