Beispiel #1
0
def mylistadd(fid, viewed, state):
    '''Issues a MYLISTADD.'''
    # Do we need to issue a MYLIST anyway? Currently, no.
    if session == None:
        return False
    command = "MYLISTADD fid=" + str(fid) + "&viewed=" + str(viewed) + "&state=" + str(state) + "&s=" + session
    internets.i.put(command)
    code = unamp(internets.o.get())[0:3]
    if code == "210":
        # Construct a fake array of data to assemble and insert into the database.
        x = db.findfid(fid)
        # I'm lazy, so one line. Look at this...
        # ["lid", "fid", "eid", "aid", "gid", "date", "state", "viewdate", "storage", "source", "lother"]
        temp = [code.split(' ')[-1], x["fid"], x["eid"], x["aid"], x["gid"], 0, int(state), 0, '', '', '']
        db.addlid(temp)
        return True
    elif code == "310":
        # Try again, with edit=1.
        lid = code.split(' ')[-1]
        command = "MYLISTADD lid=" + str(lid) + "&viewed=" + str(viewed) + "&state=" + str(state) + "&edit=1&s=" + session
        internets.i.put(command)
        code = unamp(internets.o.get())[0:3]
        if code == "311":
            # O RLY? Well, let's see this so-called "entry," and then do some progressive caching.
            # Construct a fake array of data to assemble and insert into the database.
            x = db.findfid(fid)
            # I'm lazy, so one line. Look at this...
            # ["lid", "fid", "eid", "aid", "gid", "date", "state", "viewdate", "storage", "source", "lother"]
            temp = [code.split(' ')[-1], x["fid"], x["eid"], x["aid"], x["gid"], 0, int(state), 0, '', '', '']
            db.addlid(temp)
            return True
        else:
            return False
    else:
        # FIXME: unsupported return code.
        return None
Beispiel #2
0
 def gui_tree_rc(self, event):
     popup = wx.Menu()
     treeitem = event.GetItem()
     treedata = self.tree.GetItemPyData(treeitem)
     if treedata[0] == "a":
         # Right-click on anime
         idd = wx.NewId()
         popup.Append(idd, "Remove anime " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmaid(treedata[1]), id=idd)
         idd = wx.NewId()
         popup.Append(idd, "Refresh anime " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmaid(treedata[1]) and db.findaid(treedata[1]), id=idd)
     elif treedata[0] == "ue":
         # Right-click on unidentified episode
         idd = wx.NewId()
         popup.Append(idd, "Lookup episode")
         self.Bind(wx.EVT_MENU, lambda evt: db.findeid(aid=treedata[1]), id=idd)
     elif treedata[0] == "e":
         # Right-click on known episode
         idd = wx.NewId()
         popup.Append(idd, "Remove episode " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmeid(treedata[1]), id=idd)
         idd = wx.NewId()
         popup.Append(idd, "Refresh episode " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmeid(treedata[1]) and db.findeid(treedata[1]), id=idd)
     elif treedata[0] == "f":
         # Right-click on file
         idd = wx.NewId()
         popup.Append(idd, "Remove file " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmfid(treedata[1]), id=idd)
         idd = wx.NewId()
         popup.Append(idd, "Refresh file " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmfid(treedata[1]) and db.findfid(treedata[1]), id=idd)
     idd = wx.NewId()
     popup.Append(idd, "Refresh")
     self.Bind(wx.EVT_MENU, self.gui_refresh, id=idd)
     self.PopupMenu(popup)
     event.Skip()
Beispiel #3
0
 def gui_tree_rc(self, event):
     popup = wx.Menu()
     treeitem = event.GetItem()
     treedata = self.tree.GetItemPyData(treeitem)
     if treedata[0] == "a":
         # Right-click on anime
         idd = wx.NewId()
         popup.Append(idd, "Remove anime " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmaid(treedata[1]), id=idd)
         idd = wx.NewId()
         popup.Append(idd, "Refresh anime " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmaid(treedata[1]) and db.findaid(treedata[1]), id=idd)
     elif treedata[0] == "ue":
         # Right-click on unidentified episode
         idd = wx.NewId()
         popup.Append(idd, "Lookup episode")
         self.Bind(wx.EVT_MENU, lambda evt: db.findeid(aid=treedata[1]), id=idd)
     elif treedata[0] == "e":
         # Right-click on known episode
         idd = wx.NewId()
         popup.Append(idd, "Remove episode " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmeid(treedata[1]), id=idd)
         idd = wx.NewId()
         popup.Append(idd, "Refresh episode " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmeid(treedata[1]) and db.findeid(treedata[1]), id=idd)
     elif treedata[0] == "f":
         # Right-click on file
         idd = wx.NewId()
         popup.Append(idd, "Remove file " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmfid(treedata[1]), id=idd)
         idd = wx.NewId()
         popup.Append(idd, "Refresh file " + str(treedata[1]))
         self.Bind(wx.EVT_MENU, lambda evt: db.rmfid(treedata[1]) and db.findfid(treedata[1]), id=idd)
     idd = wx.NewId()
     popup.Append(idd, "Refresh")
     self.Bind(wx.EVT_MENU, self.gui_refresh, id=idd)
     self.PopupMenu(popup)
     event.Skip()
Beispiel #4
0
 def gui_hash(self, event):  # wxGlade: oadb.<event_handler>
     print "Starting hashing..."
     if udp.session == None:
         # Huh. Sure you don't wanna login?
         x = wx.MessageBox("You are not logged in.\n\nDo you wish to proceed anyway?", "Not Logged In", wx.YES_NO)
         if x == wx.NO:
             return
     if self.starthashing.GetValue():
         """There used to be some threading code here that passed
         references from here to hash.hashthread. F**K THAT SHIT.
         GTK+, at least, doesn't like doing things like passing
         references between threads. Fortunately, the progress
         dialog is modal anyway."""
         total = self.filelist.GetItemCount()
         # hashes = []
         progdialog = wx.ProgressDialog("Currently hashing...", "Currently hashing...", (total * 25) + 1, self)
         while self.filelist.GetItemCount() > 0:
             filename = self.filelist.GetItem(0, 0).GetText()
             x = (total - self.filelist.GetItemCount()) * 25
             progdialog.Update(x, os.path.split(filename)[1])
             # hashes.append(hash.ed2k(filename))
             hasher = hash.ed2k(filename)
             datum = None
             for i in hasher:
                 x = x + 1
                 progdialog.Update(x)
                 if i != 1:
                     # On the last iteration, returns the data!
                     datum = i
                     break
             fileinfo = db.findfid(h=datum)
             del hasher
             if self.conf.get("file.move.check") or self.conf.get("file.rename.check"):
                 # Move the file!
                 if os.access(filename, os.R_OK | os.W_OK):
                     # We're okay, so let's move it...
                     (head, tail) = os.path.split(filename)
                     if self.conf.get("file.move.check"):
                         head = os.path.normpath(replace_hashes(self.conf.get("file.move.dest"), fileinfo))
                         if not os.path.exists(head):
                             try:
                                 os.makedirs(head)
                             except OSError:
                                 self.derror("Could not create directory " + head + ": Permission denied!")
                                 progdialog.Destroy()
                                 self.starthashing.SetValue(False)
                                 return
                     if self.conf.get("file.rename.check"):
                         # Confusing line. New tail is regexp plus file extension.
                         tail = (
                             replace_hashes(self.conf.get("file.rename.dest"), fileinfo) + "." + tail.split(".")[-1]
                         )
                     print "Head:", head
                     print "Tail:", tail
                     target = os.path.join(head, tail)
                     os.rename(filename, target)
                     (filename, target) = (target, None)
                 else:
                     self.derror("Could not move " + filename + ": Permission denied!")
                     progdialog.Destroy()
                     self.starthashing.SetValue(False)
                     return
                 if self.conf.get("mylist.check"):
                     # Add to mylist!
                     if not db.mylistadd(
                         fileinfo["fid"], int(self.conf.get("mylist.viewed")), self.conf.get("mylist.state")
                     ):
                         wx.MessageBox("Couldn't add a file to the mylist. This ain't good.")
             self.filelist.DeleteItem(0)
         progdialog.Update(total * 25 + 1)
         progdialog.Destroy()
         self.starthashing.SetValue(False)
         # for hash in hashes:
         # db.findfile(h=hash)
     print "Finished hashing!"
Beispiel #5
0
 def gui_hash(self, event): # wxGlade: oadb.<event_handler>
     print "Starting hashing..."
     if udp.session == None:
         # Huh. Sure you don't wanna login?
         x = wx.MessageBox("You are not logged in.\n\nDo you wish to proceed anyway?", "Not Logged In", wx.YES_NO)
         if x == wx.NO:
             return
     if self.starthashing.GetValue():
         '''There used to be some threading code here that passed
         references from here to hash.hashthread. F**K THAT SHIT.
         GTK+, at least, doesn't like doing things like passing
         references between threads. Fortunately, the progress
         dialog is modal anyway.'''
         total = self.filelist.GetItemCount()
         # hashes = []
         progdialog = wx.ProgressDialog("Currently hashing...", "Currently hashing...", (total*25)+1, self)
         while self.filelist.GetItemCount() > 0:
             filename = self.filelist.GetItem(0, 0).GetText()
             x = (total - self.filelist.GetItemCount())*25
             progdialog.Update(x, os.path.split(filename)[1])
             # hashes.append(hash.ed2k(filename))
             hasher = hash.ed2k(filename)
             datum = None
             for i in hasher:
                 x = x + 1
                 progdialog.Update(x)
                 if i != 1:
                     # On the last iteration, returns the data!
                     datum = i
                     break
             fileinfo = db.findfid(h=datum)
             del hasher
             if self.conf.get("file.move.check") or self.conf.get("file.rename.check"):
                 # Move the file!
                 if os.access(filename, os.R_OK | os.W_OK):
                     # We're okay, so let's move it...
                     (head, tail) = os.path.split(filename)
                     if self.conf.get("file.move.check"):
                         head = os.path.normpath(replace_hashes(self.conf.get("file.move.dest"), fileinfo))
                         if not os.path.exists(head):
                             try:
                                 os.makedirs(head)
                             except OSError:
                                 self.derror("Could not create directory " + head + ": Permission denied!")
                                 progdialog.Destroy()
                                 self.starthashing.SetValue(False)
                                 return
                     if self.conf.get("file.rename.check"):
                         # Confusing line. New tail is regexp plus file extension.
                         tail = replace_hashes(self.conf.get("file.rename.dest"), fileinfo) + '.' + tail.split('.')[-1]
                     print "Head:",head
                     print "Tail:",tail
                     target = os.path.join(head, tail)
                     os.rename(filename, target)
                     (filename, target) = (target, None)
                 else:
                     self.derror("Could not move " + filename + ": Permission denied!")
                     progdialog.Destroy()
                     self.starthashing.SetValue(False)
                     return
                 if self.conf.get("mylist.check"):
                     # Add to mylist!
                     if not db.mylistadd(fileinfo["fid"], int(self.conf.get("mylist.viewed")), self.conf.get("mylist.state")):
                         wx.MessageBox("Couldn't add a file to the mylist. This ain't good.")
             self.filelist.DeleteItem(0)
         progdialog.Update(total*25+1)
         progdialog.Destroy()
         self.starthashing.SetValue(False)
         #for hash in hashes:
             #db.findfile(h=hash)
     print "Finished hashing!"