[PXCDD-commit] SF.net SVN: pxcdd: [395] trunk/client/pxcddup
Status: Alpha
Brought to you by:
tangentsoft
From: <tan...@us...> - 2006-07-12 11:07:18
|
Revision: 395 Author: tangentsoft Date: 2006-07-12 04:07:14 -0700 (Wed, 12 Jul 2006) ViewCVS: http://svn.sourceforge.net/pxcdd/?rev=395&view=rev Log Message: ----------- - Added -g command line option, to make it start in file picker GUI mode; prevents command line parser from checking sanity of other command line flags, but doesn't prevent it from accepting values - -g flag causes it to redirect output streams, just as giving .ddo file does. - Split generic GUI code out of MainWindow class into new MainFrame class, and derived UploadStatusWindow from it. - Also derived new FilePickerWindow from new MainFrame class. The shared heritage lets both modes share things like the about box handler. - Starting SFTP thread from UploadStatusWindow now, instead of higher up, so it doesn't interfere with file picker GUI mode. Modified Paths: -------------- trunk/client/pxcddup/gui.py trunk/client/pxcddup/pxcddup.py trunk/client/pxcddup/sftp.py Modified: trunk/client/pxcddup/gui.py =================================================================== --- trunk/client/pxcddup/gui.py 2006-07-12 09:29:09 UTC (rev 394) +++ trunk/client/pxcddup/gui.py 2006-07-12 11:07:14 UTC (rev 395) @@ -12,8 +12,8 @@ import wx -import thread - +import thread + import os @@ -22,33 +22,32 @@ gPasswordMutex = None -#### class MainWindow ################################################## -## Class defining the application's main frame window +#### class MainFrame ################################################### -class MainWindow(wx.Frame): - """ pxcddup.py's main frame class """ +class MainFrame(wx.Frame): + """ + Class defining the common elements to all pxcddup top-level windows. + """ def __init__(self, uploader): # Call parent class to initialize the frame window itself wx.Frame.__init__(self, None, wx.ID_ANY, 'PXCDD Uploader', style = wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN) - # Init misc member variables - self.lastFile = -1 - self.percent = 0 - self.progress = None - self.uploader = uploader - - # Add the Windows icon to the window - if os.name in ("win", "nt"): - try: - import win32api - exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None)) - print exeName - icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO) - self.SetIcon(icon) - except: - print "Couldn't load icon" + # Init member variables + self.uploader = uploader + + # Add the Windows icon to the window + if os.name in ("win", "nt"): + try: + import win32api + exeName = win32api.GetModuleFileName( \ + win32api.GetModuleHandle(None)) + print exeName + icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO) + self.SetIcon(icon) + except: + print "Couldn't load icon" # Create a menu for the frame -- on OS X, this is the # application menu instead. @@ -60,14 +59,46 @@ menuBar.Append(helpMenu, "&Help") self.SetMenuBar(menuBar) - # Create the progress update timer - self.timer = wx.Timer(self) - # Bind events to handler functions - self.Bind(wx.EVT_TIMER, self.OnUpdateProgress, self.timer) wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout) wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit) + + def OnAbout(self, e): + d = wx.MessageDialog(self, u"Copyright \xA9 2006 Pixel Corps", + "PXC Digital Dailies Uploader", + wx.OK | wx.ICON_INFORMATION) + d.ShowModal() + d.Destroy() + + + def OnExit(self, e): + print "EXIT 0" + self.Shutdown() + + + def Shutdown(self): + print "IN SHUTDOWN" + self.Close() + + +#### class UploadStatusWindow ########################################## + +class UploadStatusWindow(MainFrame): + """ + Class defining the window managing user feedback for the upload + status. + """ + def __init__(self, uploader): + # Call parent class to handle basics common to all pxcddup + # top-level windows. + MainFrame.__init__(self, uploader) + + # Init member variables + self.lastFile = -1 + self.percent = 0 + self.progress = None + # Create the contents of the frame, and lay it out with sizers self.hsizer = wx.BoxSizer(wx.HORIZONTAL) numFiles = len(self.uploader.localFiles) @@ -93,22 +124,14 @@ self.Move((screenX / 2 - winX / 2, screenY / 3 - winY / 2)) # Start progress bar update timer, ticking once per second + self.timer = wx.Timer(self) + self.Bind(wx.EVT_TIMER, self.OnUpdateProgress, self.timer) self.timer.Start(1000) + # Start SFTP uploader thread + CreateSFTPThread() - def OnAbout(self, e): - d = wx.MessageDialog(self, u"Copyright \xA9 2006 Pixel Corps", - "PXC Digital Dailies Uploader", - wx.OK | wx.ICON_INFORMATION) - d.ShowModal() - d.Destroy() - - def OnExit(self, e): - print "EXIT 0" - self.Shutdown() - - def OnUpdateProgress(self, timer): if self.progress and self.percent > 0: self.progress.Update(min(self.percent, 100)) @@ -127,11 +150,6 @@ self.progress.CenterOnScreen() - def Shutdown(self): - print "IN SHUTDOWN" - self.Close() - - def UpdateProgress(self, fileNum, percent): if fileNum != self.lastFile: self.lastFile = fileNum @@ -139,6 +157,37 @@ self.percent = percent +#### class FilePickerWindow ############################################ + +class FilePickerWindow(MainFrame): + """ + Class defining the file picker / slate info gathering window, shown + before the upload status window when pxcddup is run with the -g flag. + """ + def __init__(self, uploader): + # Call parent class to handle basics common to all pxcddup + # top-level windows. + MainFrame.__init__(self, uploader) + + # Create the contents of the frame, and lay it out with sizers + self.hsizer = wx.BoxSizer(wx.HORIZONTAL) + numFiles = len(self.uploader.localFiles) + if numFiles == 1: plural = '' + else: plural = 's' + self.statusText = wx.StaticText(self, wx.ID_ANY, + "Pick some files, eh?", style = wx.ALIGN_CENTRE) + self.hsizer.Add(self.statusText, 1, wx.EXPAND | wx.ALL, + border = 10) + self.vsizer = wx.BoxSizer(wx.VERTICAL) + self.vsizer.Add(self.hsizer, 1, wx.EXPAND) + self.SetAutoLayout(True) + self.SetSizerAndFit(self.vsizer) + self.SetClientSize(self.vsizer.GetSize()) + + # Now that we know the frame size, center it on the screen + self.Center() + + #### class EmulateSynchronous ########################################## # This class uses mutexes to emulate a synchronous call to a function # running in the GUI thread from another thread. The calling thread @@ -245,11 +294,18 @@ def StartApp(uploader): app = wx.PySimpleApp() - frame = MainWindow(uploader) + + if uploader.filePickerGUI: + print "Creating file picker GUI..." + frame = FilePickerWindow(uploader) + else: + print "Creating upload status window..." + frame = UploadStatusWindow(uploader) frame.Show() + app.SetTopWindow(frame) + try: - CreateSFTPThread() print "MAIN LOOP START" app.MainLoop() print "MAIN LOOP EXIT" Modified: trunk/client/pxcddup/pxcddup.py =================================================================== --- trunk/client/pxcddup/pxcddup.py 2006-07-12 09:29:09 UTC (rev 394) +++ trunk/client/pxcddup/pxcddup.py 2006-07-12 11:07:14 UTC (rev 395) @@ -16,15 +16,30 @@ import getopt, os, posixpath, sys +def RedirectOutputToLog(): + """ + Open a debug log in the temp directory, and redirect stdout and + stderr to it. + """ + + logFile = '%s/pxcddup-debug.txt' % (GetTempPath()) + try: + sys.stderr = sys.stdout = open(logFile, 'w') + except: + print "Could not open log file '%s'!" % (logFile) + + def usage(): """Print the program's usage message""" print """ -usage: pxcddup.py [-h hostname] [-r remote-dir] [-u username] +usage: pxcddup.py [-g] + [-h hostname] [-r remote-dir] [-u username] [-P pxc-team] [-A author] [-D desc] [-M modifier] [-T type] files... - -h host name of server to SFTP file to + -h host name of server to SFTP file to + -g get upload parameters from GUI instead of command line -m upload new / modified files only -p port number on SFTP server to use (default is 22) -r directory on SFTP server to place file into @@ -47,6 +62,8 @@ You must give either -r, or -P, and there must be at least one file argument. If you give -h, you must also give -u. You can leave out -h and -r if you give -P, but -u is still required. + + If you give -g, it overrides all other requirements. """ @@ -72,43 +89,38 @@ # Get program options from argument file, if it is given opts = None args = None - try: - if len(sys.argv) == 2: - tmpDir = GetTempPath() - - # Open a debug log in that temp directory, and redirect - # stdout and stderr to it. - logFile = '%s/pxcddup-debug.txt' % (tmpDir) - try: - sys.stdout = open(logFile, 'w') - except: - print "Could not open log file '%s'!" % (logFile) - sys.stderr = sys.stdout - - # Slurp the options file's contents in + if len(sys.argv) == 2 and sys.argv[1][0] != '-': + try: + # We've apparently been given a .ddo file, so send + # stdout and stderr to a debug log and then slurp + # the options file's contents in. + RedirectOutputToLog() argFile = open(sys.argv[1]) sys.argv.pop() exec(argFile) - except: - print "Argument file ", sys.argv[1], " does not exist!" - return False + except: + print "Argument file %s does not exist!" % sys.argv[1] + return False # Get program options from command line, if any were given if len(sys.argv) > 1: - opts, args = getopt.getopt(sys.argv[1:], "d:h:mp:r:su:A:D:M:P:T:J:S:E:U:N:") + opts, args = getopt.getopt(sys.argv[1:], \ + "d:gh:mp:r:su:A:D:M:P:T:J:S:E:U:N:") elif not opts: print "No arguments given!" usage() return False - # Save data given as command line options to global variables, - # doing basic checks on the values. + # Save data given as command line options, doing basic checks + # on the values. for opt, val in opts: if opt == '-d': os.chdir(val) + elif opt == '-g': + uploader.filePickerGUI = True elif opt == '-h': - uploader.hostName = val - elif opt == '-m': + uploader.hostName = val + elif opt == '-m': uploader.modOnly = True elif opt == '-p': port = int(val) @@ -163,7 +175,7 @@ # upload. if args: uploader.localFiles = args - else: + elif not uploader.filePickerGUI: print 'No files to upload!' usage() return False @@ -177,14 +189,16 @@ ## that they are, collectively, reasonable. if uploader.remoteDir or pxcTeam: # Make sure we have enough info to get onto the file server. - if pxcTeam and uploader.userName: + if uploader.filePickerGUI: + print 'File picker GUI mode selected...' + elif pxcTeam and uploader.userName: uploader.hostName = 'teams.pixelcorps.com' uploader.remoteDir = '/home/teams/tms_%s/uploads' % \ (pxcTeam) elif not (uploader.hostName and uploader.remoteDir and uploader.userName): print 'Not enough information to infer upload location. You must' - print 'give either -P and -u or -h, -r, and -u.' + print 'give either -g, or -P and -u, or -h, -r, and -u.' usage() return False @@ -221,8 +235,12 @@ return False return True + elif uploader.filePickerGUI: + RedirectOutputToLog() + print 'Output streams redirected, starting file picker GUI...' + return True else: - print 'You must give the one of -r or -P' + print 'You must give the one of -g, -r or -P' usage() return False Modified: trunk/client/pxcddup/sftp.py =================================================================== --- trunk/client/pxcddup/sftp.py 2006-07-12 09:29:09 UTC (rev 394) +++ trunk/client/pxcddup/sftp.py 2006-07-12 11:07:14 UTC (rev 395) @@ -35,8 +35,9 @@ chunkSize = 4096 def __init__(self): + self.filePickerGUI = False + self.hostName = None self.localFiles = [] - self.hostName = None self.port = 22 self.remoteDir = None self.remoteFiles = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |