6 this file is part of the project scolasync
8 Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import os.path, dbus, subprocess, time, random
28 from globaldef
import markFileName
31 liste statique pour éviter de demander chaque seconde le nom d'un
32 propriétaire de clé si on n'a pas souhaité le donner.
42 tattooFileName = os.path.join(mountPoint,
".scolasync-tattoo")
44 if os.path.exists(tattooFileName):
45 tattoo_=open(tattooFileName,
"r").readlines()[0].strip()
50 tattoo_=
"%12.2f" %time.time()
56 outfile=open(tattooFileName,
"w")
57 outfile.write(tattoo_)
69 title=QApplication.translate(
"Dialog",
"Choix du propriétaire",
None)
70 prompt=QApplication.translate(
"Dialog",
"Nouveau nom du propriétaire du baladeur",
None)
71 newStudent, ok = QInputDialog.getText(
None, title, prompt, text=hint)
73 newStudent=
"%s" %newStudent
75 db.writeStudent(ud.stickid, ud.uuid, ud.tattoo(), newStudent)
101 def __init__(self, path, mp='', isUsb=False, vendor='', model='', parent=None,
102 fstype='', serial='', uuid='',
103 free=0, capacity=0, device='', firstFat=None, selected=True):
104 usbDisk2.uDisk2.__init__(self, path=path, mp=mp, isUsb=isUsb, vendor=vendor,
105 model=model, parent=parent, fstype=fstype, serial=serial,
106 uuid=uuid, free=free, capacity=capacity, device=device,
107 firstFat=firstFat, selected=selected)
108 QObject.__init__(self)
117 return self.
getFat().owner
134 prefix=
"\n"+
" "*indent
136 props=[
"mp",
"parent",
"fstype",
"stickid",
"uuid",
"vendor",
"model",
"devStuff",
"free",
"capacity",
"owner"]
138 r+=prefix+
"%s = %s" %(prop, getattr(self,prop))
167 f1=
"/usr/share/scolasync/marques.py"
168 f2=os.path.expanduser(markFileName)
169 if os.path.exists(f2):
175 result=eval(open(f,
"r", encoding=
"utf-8").read())
200 result=usbDisk2.uDisk2.headers(locale)
201 ownerProp=QApplication.translate(
"uDisk",
"owner",
None)
202 result.insert(1,ownerProp)
213 return QApplication.translate(
"Dialog",
"inconnu",
None)
222 propListe=usbDisk2.uDisk2.headers()
233 headers = staticmethod(headers)
247 if not db.knowsId(ud.stickid, ud.uuid, ud.tattoo()) :
250 prompt=QApplication.translate(
"Dialog",
"La cle {id}<br>n'est pas identifiee, donnez le nom du proprietaire",
None).format(id=ud.stickid)
251 title=QApplication.translate(
"Dialog",
"Entrer un nom",
None)
252 text,ok = QInputDialog.getText(
None, title, prompt)
253 db.writeStudent(ud.stickid, ud.uuid, ud.tattoo(), text)
254 o=db.readStudent(ud.stickid, ud.uuid, ud.tattoo())
266 for i
in range(length):
267 result+=random.choice(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
286 def __init__(self, access="disk", diskClass=uDisk2, ownerDialog=False):
288 usbDisk2.Available.__init__(self, access, diskClass)
302 if __name__==
"__main__":
308 QMainWindow.__init__(self)
311 quitbutton = QPushButton(
'Examinez le terminal\nbranchez et débranchez des clés USB, puis\nQuittez', self)
312 quitbutton.clicked.connect(self.close)
313 self.setCentralWidget(quitbutton)
319 print([s.split(
"/")[-1]
for s
in machin.targets.keys()])
320 for t
in machin.targets:
321 machin.targets[t].owner=machin.targets[t].ownerByDb()
322 print (machin.targets[t].owner,
":", t)
323 machin.modified=
False
324 machin.addHook(
'object-added', print_targets_if_modif)
325 machin.addHook(
'object-removed', print_targets_if_modif)
327 app = QApplication(sys.argv)
330 sys.exit(app.exec_())