Avdump GUI: Difference between revisions

Jump to navigation Jump to search
1,274 bytes added ,  13 May 2007
v1.02 added nagscreens to prevent the worst bugs + catching a couple more exceptions
(v1.01 fixing problems with \ at the end of the scanpath)
(v1.02 added nagscreens to prevent the worst bugs + catching a couple more exceptions)
Line 1: Line 1:
<pre>
<pre>
import wx,os,subprocess
import wx,os,subprocess
class stuff:
    def read_file(self,filepath):
        """reads a file and returns the containing text"""
        f = open(filepath,"r")
        config = f.readlines()
        f.close()
        return config
    def create_file(self,filepath,new):
        """writes content to a not existing file"""
        f = open(filepath,"w")
        f.write(new)
        f.close()


class mainFrame(wx.Frame):
class mainFrame(wx.Frame):
Line 20: Line 6:
     __options = {'avdump':'avdump.exe','user':'','pass':'','ext':'','misc':'','bsize':'2048','port':'','tout':'30','retries':'6','exp':'export.txt','log':'log.txt','done':'done.txt'}
     __options = {'avdump':'avdump.exe','user':'','pass':'','ext':'','misc':'','bsize':'2048','port':'','tout':'30','retries':'6','exp':'export.txt','log':'log.txt','done':'done.txt'}
     __configfile='config.ini'
     __configfile='config.ini'
   
 
     def read_config(self):
     def read_config(self,newconfig=''):
         '''read the config file and return the content'''
         '''read the config file and return the content'''
         if not os.path.exists(self.__configfile):
         if not os.path.exists(self.__configfile):
             self.write_config()
             for elem in self.__options:
         for line in glob.read_file(self.__configfile):
                newconfig += ('%s=%s\n') %(elem,self.__options[elem])
            open(self.__configfile,"w").write(newconfig)
         for line in open(self.__configfile,"r").readlines():
             if not line.endswith('='):
             if not line.endswith('='):
                 temp,val = line.rstrip('\n').split('=',1)
                 temp,val = line.rstrip('\n').split('=',1)
Line 33: Line 21:
                 if temp == elem:
                 if temp == elem:
                     self.__options[temp] = val
                     self.__options[temp] = val
    def write_config(self,newconfig=''):
        for elem in self.__options:
            newconfig += ('%s=%s\n') %(elem,self.__options[elem])
        glob.create_file(self.__configfile,newconfig)


     def __init__(self, parent, title):
     def __init__(self, parent, title):
         wx.Frame.__init__(self, parent, -1, u'Avdump GUI', wx.DefaultPosition, (350, 140), style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 0 | 0 | wx.MINIMIZE_BOX)
         wx.Frame.__init__(self, parent, -1, u'Avdump GUI', wx.DefaultPosition, (350, 140), style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 0 | 0 | wx.MINIMIZE_BOX)
         self.panel = wx.Panel(self, -1)
         self.panel = wx.Panel(self, -1)
         self.filepath = wx.TextCtrl(self.panel, -1, '', (95, 25), size=(190, 24))
         self.filepath = wx.TextCtrl(self.panel, -1, '', (95, 25), size=(190, 24))
         self.start = wx.Button(self.panel, -1, 'Start', (90,75), (-1, -1))
         self.start = wx.Button(self.panel, -1, 'Start', (90,75), (-1, -1))
Line 48: Line 30:
         self.select = wx.Button(self.panel, -1, '...', (295, 25), (25, -1))
         self.select = wx.Button(self.panel, -1, '...', (295, 25), (25, -1))
         self.scantype = wx.RadioBox(self.panel,-1,pos=(5,5),size=(-1, 59),style=wx.RA_VERTICAL,label='scantype',choices = ['Files','Folder'])
         self.scantype = wx.RadioBox(self.panel,-1,pos=(5,5),size=(-1, 59),style=wx.RA_VERTICAL,label='scantype',choices = ['Files','Folder'])
       
         self.Bind(wx.EVT_BUTTON, self.selectClick, self.select)
         self.Bind(wx.EVT_BUTTON, self.selectClick, self.select)
         self.Bind(wx.EVT_BUTTON, self.optionsClick, self.options)
         self.Bind(wx.EVT_BUTTON, self.optionsClick, self.options)
         self.Bind(wx.EVT_BUTTON, self.startClick, self.start)
         self.Bind(wx.EVT_BUTTON, self.startClick, self.start)
        self.read_config()
         self.child = OptionsFrame(self, 'App')
         self.child = OptionsFrame(self, 'App')
        self.child.read_config()


     def selectClick(self, event,path=''):
     def selectClick(self, event,path=''):
Line 70: Line 50:
             if dialog.ShowModal() == wx.ID_OK:
             if dialog.ShowModal() == wx.ID_OK:
                 path = '"' + dialog.GetPath().rstrip("\\") + '"'
                 path = '"' + dialog.GetPath().rstrip("\\") + '"'
         self.filepath.Clear()
         self.filepath.Clear()
         dialog.Destroy()
         dialog.Destroy()
Line 77: Line 56:


     def startClick(self, event):
     def startClick(self, event):
        self.read_config()
         self.__options['param'] = ''
         self.__options['param'] = ''
         if self.filepath.GetValue() != '':
         if self.filepath.GetValue() == '':
             self.read_config()
            self.child.error('You have to select some files or folder to scan!')
        elif (self.__options['user'] == '' or self.__options['pass'] == ''):
             self.child.error("You didn't enter your username and/or password in the options menu.")
        elif self.__options['avdump'] == '':
            self.child.error('You must specify the path to avdump.exe!')
        elif self.__options['avdump'] == 'avdump.exe':
            self.child.info('You should set the _absolute_ path to avdump.exe.\nOtherwise complications might arise.')
        else:
             if self.__options['misc'].lstrip(',') > 0:
             if self.__options['misc'].lstrip(',') > 0:
                 for elem in self.__options['misc'].split(','):
                 for elem in self.__options['misc'].split(','):
Line 89: Line 76:
                         else:
                         else:
                             self.__options['param'] += ' -' + elem + ':' + self.__options[elem]
                             self.__options['param'] += ' -' + elem + ':' + self.__options[elem]
             subprocess.call(('"%s" -ac:%s:%s%s %s') %(self.__options['avdump'], self.__options['user'], self.__options['pass'], self.__options['param'], self.__options['scanpath']))
             subprocess.call(('%s -ac:%s:%s%s %s') %(self.__options['avdump'], self.__options['user'], self.__options['pass'], self.__options['param'], self.__options['scanpath']))


     def optionsClick(self, event):
     def optionsClick(self, event):
        self.child.refresh()
         self.child.Show(True)
         self.child.Show(True)


Line 103: Line 91:
         if not os.path.exists(self.__configfile):
         if not os.path.exists(self.__configfile):
             self.write_config()
             self.write_config()
         for line in glob.read_file(self.__configfile):
         for line in open(self.__configfile,"r").readlines():
             if not line.endswith('='):
             if not line.endswith('='):
                 temp,val = line.rstrip('\n').split('=',1)
                 temp,val = line.rstrip('\n').split('=',1)
Line 115: Line 103:
         for elem in self.__options:
         for elem in self.__options:
             newconfig += ('%s=%s\n') %(elem,self.__options[elem])
             newconfig += ('%s=%s\n') %(elem,self.__options[elem])
        glob.create_file(self.__configfile,newconfig)
            open(self.__configfile,"w").write(newconfig)


     def set_misc(self,misc=''):
     def set_misc(self,misc=''):
Line 132: Line 120:
                 self.__box[misc] = True
                 self.__box[misc] = True


   
     def __init__(self, parent, title):
     def __init__(self, parent, title):
         wx.Frame.__init__(self, parent, -1, 'options', wx.DefaultPosition, (301, 691), style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 0 | 0 | wx.MINIMIZE_BOX)
         wx.Frame.__init__(self, parent, -1, 'options', wx.DefaultPosition, (301, 691), style=wx.CLOSE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 0 | 0 | wx.MINIMIZE_BOX)
Line 193: Line 180:
         if dialog.ShowModal() == wx.ID_OK:
         if dialog.ShowModal() == wx.ID_OK:
             self.filepath.Clear()
             self.filepath.Clear()
             self.filepath.write(dialog.GetPath())
             self.filepath.write('"' + dialog.GetPath().rstrip("\\") + '"')


     def selectlogClick(self, event):
     def selectlogClick(self, event):
Line 199: Line 186:
         if dialog.ShowModal() == wx.ID_OK:
         if dialog.ShowModal() == wx.ID_OK:
             self.logpath.Clear()
             self.logpath.Clear()
             self.logpath.write(dialog.GetPath())
             self.logpath.write('"' + dialog.GetPath().rstrip("\\") + '"')


     def selectexpClick(self, event):
     def selectexpClick(self, event):
Line 205: Line 192:
         if dialog.ShowModal() == wx.ID_OK:
         if dialog.ShowModal() == wx.ID_OK:
             self.exppath.Clear()
             self.exppath.Clear()
             self.exppath.write(dialog.GetPath())
             self.exppath.write('"' + dialog.GetPath().rstrip("\\") + '"')


     def selectdoneClick(self, event):
     def selectdoneClick(self, event):
Line 211: Line 198:
         if dialog.ShowModal() == wx.ID_OK:
         if dialog.ShowModal() == wx.ID_OK:
             self.donepath.Clear()
             self.donepath.Clear()
             self.donepath.write(dialog.GetPath())
             self.donepath.write('"' + dialog.GetPath().rstrip("\\") + '"')


     def saveClick(self,event):
     def saveClick(self,event):
         self.update()
         self.update()
         self.Show(False)
         if self.__options['avdump'] == '':
            self.error('You must specify the path to avdump.exe!')
        elif self.__options['avdump'] == 'avdump.exe':
            self.info('You should set the _absolute_ path to avdump.exe.\nOtherwise complications might arise.')
        else:
            self.Show(False)


     def cancelClick(self,event):
     def cancelClick(self,event):
Line 228: Line 220:
         self.get_checkboxes(self.__options['misc'])
         self.get_checkboxes(self.__options['misc'])
         self.filepath.Clear()
         self.filepath.Clear()
         self.filepath.write(self.__options['avdump'])
         self.filepath.write(self.__options['avdump'].rstrip('"').lstrip('"'))
         self.username.Clear()
         self.username.Clear()
         self.username.write(self.__options['user'])
         self.username.write(self.__options['user'])
Line 244: Line 236:
         self.retries.write(self.__options['retries'])
         self.retries.write(self.__options['retries'])
         self.exppath.Clear()
         self.exppath.Clear()
         self.exppath.write(self.__options['exp'])
         self.exppath.write(self.__options['exp'].rstrip('"').lstrip('"'))
         self.logpath.Clear()
         self.logpath.Clear()
         self.logpath.write(self.__options['log'])
         self.logpath.write(self.__options['log'].rstrip('"').lstrip('"'))
         self.donepath.Clear()
         self.donepath.Clear()
         self.donepath.write(self.__options['done'])
         self.donepath.write(self.__options['done'].rstrip('"').lstrip('"'))
         self.ext.SetValue(self.__box['ext'])
         self.ext.SetValue(self.__box['ext'])
         self.log.SetValue(self.__box['log'])
         self.log.SetValue(self.__box['log'])
Line 268: Line 260:
         self.__options['pass'] = self.password.GetValue()
         self.__options['pass'] = self.password.GetValue()
         self.__options['ext'] = self.extention.GetValue()
         self.__options['ext'] = self.extention.GetValue()
        temp = int(self.buffersize.GetValue())
         '''make sure it's mod 8 and at least 256kb'''
         '''make sure it's mod 8 and at least 256kb'''
         if int(temp) < 256:
         try:
            temp = 256
            temp = int(self.buffersize.GetValue())
        if not temp % 8:
            if int(temp) < 256:
            temp = temp - (temp%8)
                temp = 256
            if not temp % 8:
                temp = temp - (temp%8)
        except:
            temp = 2048
         self.__options['bsize'] = unicode(temp)
         self.__options['bsize'] = unicode(temp)
         self.__options['port'] = self.portnumber.GetValue()
         try:
            int(self.portnumber.GetValue())
            self.__options['port'] = self.portnumber.GetValue()
        except:
            self.__options['port'] = ''
         self.__options['tout'] = self.timeout.GetValue()
         self.__options['tout'] = self.timeout.GetValue()
         temp = int(self.timeout.GetValue())
         temp = int(self.timeout.GetValue())
         '''make sure it's at least 20'''
         '''make sure it's at least 20'''
         if int(temp) < 20:
         try:
             temp = 20
            if int(temp) < 20:
                temp = 20
        except:
             temp = 30
         self.__options['tout'] = unicode(temp)
         self.__options['tout'] = unicode(temp)
         self.__options['retries'] = self.retries.GetValue()
         try:
            int(self.retries.GetValue())
            self.__options['retries'] = self.retries.GetValue()
        except:
            self.__options['retries'] = 6
         self.__options['exp'] = self.exppath.GetValue()
         self.__options['exp'] = self.exppath.GetValue()
         self.__options['log'] = self.logpath.GetValue()
         self.__options['log'] = self.logpath.GetValue()
Line 302: Line 308:
         self.write_config()
         self.write_config()


    def error(self,text):
        message = wx.MessageDialog(self,text,style=wx.ICON_ERROR | wx.OK)
        message.ShowModal()
    def info(self,text):
        message = wx.MessageDialog(self,text,style=wx.ICON_INFORMATION | wx.OK)
        message.ShowModal()
       
class App(wx.App):
class App(wx.App):
     def OnInit(self):
     def OnInit(self):
Line 310: Line 324:


if __name__ == '__main__':
if __name__ == '__main__':
    glob = stuff()
     app = App(True)
     app = App(True)
     app.MainLoop()
     app.MainLoop()
</pre>
</pre>

Navigation menu

MediaWiki spam blocked by CleanTalk.
MediaWiki spam blocked by CleanTalk.