Ci ricordiamo dell'utente utilizzato l'ultima volta.
Leonardo Robol [2010-12-12 16:50]
Ci ricordiamo dell'utente utilizzato l'ultima volta.
diff --git a/DrPrintGui/MainWin.py b/DrPrintGui/MainWin.py
index 4b1f857..c14229c 100644
--- a/DrPrintGui/MainWin.py
+++ b/DrPrintGui/MainWin.py
@@ -78,13 +78,13 @@ class MainWin(gtk.Window):
label = LeftAlignedLabel("<b>Autenticazione (sui computer dell'Aula 4)</b>")
- layout_box.pack_start( label )
+ layout_box.pack_start(label)
label.show()
hosts = ['ssh.dm.unipi.it', 'ssh1.dm.unipi.it', 'ssh2.dm.unipi.it']
self.auth_block = AuthBlock(self.default_spacing, 10, user = self.user,
default_hosts = hosts)
- layout_box.pack_start ( self.auth_block )
+ layout_box.pack_start(self.auth_block)
self.auth_block.show()
# The PDF file loading and print settings
@@ -193,6 +193,14 @@ class MainWin(gtk.Window):
remote_host = self.auth_block.get_remote_host ()
resp = gtk.RESPONSE_OK
+
+ # Proviamo a salvare l'utente utilizzato. Se non ci si riesce
+ # non ci lamentiamo troppo.
+ try:
+ with open(os.path.expanduser("~/.drprint"), "w") as handle:
+ handle.write(username)
+ except OSError:
+ pass
if not (filename.lower().endswith("pdf") |
filename.lower().endswith("ps") |
diff --git a/drprint b/drprint
index 1e777d4..a938bdd 100755
--- a/drprint
+++ b/drprint
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-import gtk, pygtk
+import gtk, pygtk, os
from optparse import OptionParser
from DrPrintGui.MainWin import MainWin
from DrPrintBackend import Backend
@@ -25,9 +25,20 @@ if __name__ == "__main__":
# The backend doing network work.
backend = Backend()
+ # If no user is provided on command line,
+ # check if a file .drprint exists in the
+ # home directory
+ configuration_file = os.path.expanduser("~/.drprint")
+ if option.user is None and os.path.exists(configuration_file):
+ with open(configuration_file, "r") as handle:
+ content = handle.read()
+ user = content.strip()
+ else:
+ user = option.user
+
# ...and the Gtk main window.
mw = MainWin(backend = backend,
- user = option.user,
+ user = user,
filename = filename)
## Show all :)