예제 #1
0
    def after_login(self, data, error):
        xml, errdict = data
        if errdict['err_no'] == 257:  #Need verification Code
            codestring = errdict['codeString']
            url = 'https://passport.baidu.com/cgi-bin/genimage?' + codestring

            vd = VcodeDialog(self, url)
            vd.run()
            vf = vd.get_user_input()
            if not vf or len(vf) != 4:
                self.info_label.set_text(
                    "Verification Code missing or incorrect!")
                return
            else:
                vd.destory()
            utils.async_call(auth.relogin,
                             rsakey,
                             pubkey,
                             self.username,
                             self.password,
                             vf,
                             codeString,
                             callback=self.after_login)

        elif errdict['err_no'] == 0:
            self.info_label.set_text("Login Successfully!")
            self.hide()
        self.spinn.destroy()
예제 #2
0
	def on_start_task_button_clicked(self,*arg):
		if self.is_current_selection_null(): 
			return
		self.spinn = SpinnerDialog(self)
		self.spinn.show()
		store,treepaths = self.current_selection
		self.q = queue.LifoQueue()

		for tpath in treepaths:
		
			print(store[tpath][2],store[tpath][4])
			row = store[tpath]
			num = row[0]
			filename = row[2]
			path = row[4]
			isdir = row[5]
			fsid = row[6] 
			spath = row[8]
			if not self.in_list(row,self.downlink):
				print(filename,fsid)
				npath = os.path.join(path,filename)
				utils.async_call(cloudapi.get_dlink,self.tokens,fsid,npath,num,
						 callback=self.get_down_link)
				self.downlink.append((filename,None,spath,fsid))
		print('0000sync888',self.downlink)
예제 #3
0
	def on_remove_task_button_clicked(self,*arg):
		def is_current_selection_null():
			if not self.current_selection or not self.current_selection[1] :
				dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
		        Gtk.ButtonsType.OK, "Attention.......")
				dialog.format_secondary_text("NO File is selected.!")
				dialog.run()
				dialog.destroy()
				return True
			else:	
				return False
		def after_delete_task(data,error):
			self.info_label.set_text("Deletion is done")
			self.init_view(self.bdstoken)
			self.spinn.destroy()

		if is_current_selection_null(): 
			return
		store,treepaths = self.current_selection
	

		for tpath in treepaths:
			task = ()
			for i in store[tpath]:
				task = task + (i,)
				
			task_id = task[5]
			self.spinn = SpinnerDialog(self)
			self.spinn.show()
			self.info_label.set_text("Deleting task %s "%task[1])
			utils.async_call(cloudapi.delete_task, self.bdstoken,task_id ,
						 callback=after_delete_task)
예제 #4
0
    def on_start_task_button_clicked(self, *arg):
        if self.is_current_selection_null():
            return
        self.spinn = SpinnerDialog(self)
        self.spinn.show()
        store, treepaths = self.current_selection
        self.q = queue.LifoQueue()

        for tpath in treepaths:

            print(store[tpath][2], store[tpath][4])
            row = store[tpath]
            num = row[0]
            filename = row[2]
            path = row[4]
            isdir = row[5]
            fsid = row[6]
            spath = row[8]
            if not self.in_list(row, self.downlink):
                print(filename, fsid)
                npath = os.path.join(path, filename)
                utils.async_call(cloudapi.get_dlink,
                                 self.tokens,
                                 fsid,
                                 npath,
                                 num,
                                 callback=self.get_down_link)
                self.downlink.append((filename, None, spath, fsid))
        print('0000sync888', self.downlink)
예제 #5
0
	def after_query_task(self,*arg):
		taskdata,error = arg
		taskjson,task_id = taskdata
		#self.init_view(self.bdstoken)
		#taskjson = cloudapi.query_task(task_id)
		logger.debug("taskjson: %s "%taskjson)
		#if task_json:
		file_size = int(taskjson['task_info'][task_id]['file_size'])
		finished_size = int(taskjson['task_info'][task_id]['finished_size'])
		task_name  = taskjson['task_info'][task_id]['task_name']
		logger.debug("file_size: %s "%file_size)
		logger.debug("finished_size: %s "%finished_size)


		if finished_size/file_size < 1 :
			info = "%s : Finished rate is less than 0.6, canceling."%task_name
			logger.info(info)
			self.info_label.set_text(info)
			utils.async_call(cloudapi.cancel_task, self.bdstoken,task_id,task_name,
					 callback=self.after_cancel_task)

		else:
			info = "Task:%s,id:%s is successfully created."%(task_name,task_id)
			logger.info(info)
			self.info_label.set_text(info)
			#self.init_view(self.bdstoken)
			self.spinn.destroy()
예제 #6
0
    def after_get_token(self, token, error):

        self.token = token
        self.info_label.set_text("Geting public key")
        utils.async_call(auth.get_public_key,
                         self.token,
                         callback=self.after_get_public_key)
예제 #7
0
	def after_get_public_key(self,data,error):
		rsakey,pubkey = data
		
		self.info_label.set_text("Loging in now")
		#xml = auth.login(rsakey,pubkey,self.username,self.password,self.token)
		utils.async_call(auth.login,rsakey,pubkey,self.username,self.password,self.token,
							 callback=self.after_login)
예제 #8
0
 def __init__(self):
     
     self.conn, self.chan = create_basic_channel()
 
     self.chan.exchange_declare(exchange=TASK_EXH, exchange_type="topic", durable=True)
     self.chan.queue_declare(queue=TASK_QUE, durable=True)
 
     self.chan.queue_declare(queue=STAT_QUE, durable=True)
     self.chan.basic_consume(self.on_response, queue=STAT_QUE)
     async_call(self.chan.start_consuming)
예제 #9
0
    def after_get_public_key(self, data, error):
        rsakey, pubkey = data

        self.info_label.set_text("Loging in now")
        #xml = auth.login(rsakey,pubkey,self.username,self.password,self.token)
        utils.async_call(auth.login,
                         rsakey,
                         pubkey,
                         self.username,
                         self.password,
                         self.token,
                         callback=self.after_login)
예제 #10
0
    def login(self, widget, data=None):

        self.error_label.hide()

        username = self.username_entry.get_text()

        password = self.password_entry.get_text()
        cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
        self.window.get_window().set_cursor(cursor)
        self.login_button.set_sensitive(False)
        self.username_entry.set_sensitive(False)
        self.password_entry.set_sensitive(False)
        async_call(self.auth.authenticate, self.auth_cbk, username, password)
예제 #11
0
    def on_click_login(self, button):
        self.username = self.uentry.get_text()
        self.password = self.pentry.get_text()
        if not self.username or not self.password:
            self.info_label.set_text("Username or Password is blank.")
            return
        self.info_label.set_text("Going to index")
        logger.info("Username|Password %s %s" % (self.username, self.password))
        self.spinn = SpinnerDialog(self)
        self.spinn.show()
        utils.async_call(auth.index, callback=self.after_goto_index)
        #bdstoken,sign1,sign3,timestamp = auth.index()

        print("click")
예제 #12
0
	def after_add_task(self,*arg):
		taskjson,error = arg
		logger.debug("taskjson: %s "%taskjson)
		if 'task_id' in taskjson.keys():
			task_id = str(taskjson['task_id'])
			utils.async_call(cloudapi.query_task, self.bdstoken,task_id,
				     callback=self.after_query_task)

		else:
			error = taskjson['error_msg']
			logger.info(error)
			self.info_label.set_text(error)
			#self.init_view(self.bdstoken)
			self.spinn.destroy()
예제 #13
0
    def after_goto_index(self, data, error):
        print(data)
        bdstoken, sign1, sign3, timestamp = data
        if not bdstoken:

            self.info_label.set_text("Geting token")

            #token = auth.get_token()
            utils.async_call(auth.get_token, callback=self.after_get_token)

        else:
            info = "bdstoken %s existing,no need to login again!" % bdstoken
            logger.info(info)
            self.info_label.set_text(info)
            self.spinn.destroy()
예제 #14
0
	def after_goto_index(self,data,error):
		print(data)
		bdstoken,sign1,sign3,timestamp = data
		if not bdstoken:

			self.info_label.set_text("Geting token")
			
			#token = auth.get_token()
			utils.async_call(auth.get_token, 
							 callback=self.after_get_token)

		else:
			info = "bdstoken %s existing,no need to login again!"%bdstoken
			logger.info(info)
			self.info_label.set_text(info)
			self.spinn.destroy()
예제 #15
0
	def on_click_login(self,button):
		self.username = self.uentry.get_text()
		self.password = self.pentry.get_text()
		if not self.username or not self.password:
			self.info_label.set_text("Username or Password is blank.")
			return
		self.info_label.set_text("Going to index")
		logger.info("Username|Password %s %s"%(self.username,self.password))
		self.spinn = SpinnerDialog(self)
		self.spinn.show()
		utils.async_call(auth.index,
							 callback=self.after_goto_index)
		#bdstoken,sign1,sign3,timestamp = auth.index()


		print("click")
예제 #16
0
	def after_login(self,data,error):
		xml,errdict = data
		if errdict['err_no']  == 257 : #Need verification Code
			codestring = errdict['codeString'] 
			url = 'https://passport.baidu.com/cgi-bin/genimage?' + codestring
			
			vd = VcodeDialog(self,url)
			vd.run()
			vf = vd.get_user_input()
			if not vf or len(vf) != 4:
				self.info_label.set_text("Verification Code missing or incorrect!")
				return
			else:
				vd.destory()
			utils.async_call(auth.relogin,rsakey,pubkey,self.username,self.password,vf,codeString,
							 callback=self.after_login)

		elif errdict['err_no']  == 0: 
			self.info_label.set_text("Login Successfully!")
			self.hide()
		self.spinn.destroy()
예제 #17
0
	def init_view(self,path):
		self.current_selection = None
		self.current_path = path
		logger.debug("Current Path: %s"%self.current_path)
		#list_json = cloudapi.list_path(self.current_path,500,
		#								settings.DRY,self.bdstoken)
		utils.async_call(cloudapi.list_path, self.current_path,500,
										settings.DRY,self.bdstoken,
				     callback=self.populate_view)
		#logger.debug("Size of list json: %s"%str(len(list_json)))
		#file_list = cloudapi.get_list(list_json)
		#logger.debug("Size of file_list: %s"%str(len(file_list)))
		#self.liststore.clear()
		#self.fill_liststore(file_list)
		#self.loading_spin.start()
		#self.loading_spin.show_all()
		self.spinn = SpinnerDialog(self)
		self.spinn.show()
		file_list = []
		pix_list = self.get_pix_list(file_list)
		self.fill_liststore(pix_list)
예제 #18
0
 def init_view(self, path):
     self.current_selection = None
     self.current_path = path
     logger.debug("Current Path: %s" % self.current_path)
     #list_json = cloudapi.list_path(self.current_path,500,
     #								settings.DRY,self.bdstoken)
     utils.async_call(cloudapi.list_path,
                      self.current_path,
                      500,
                      settings.DRY,
                      self.bdstoken,
                      callback=self.populate_view)
     #logger.debug("Size of list json: %s"%str(len(list_json)))
     #file_list = cloudapi.get_list(list_json)
     #logger.debug("Size of file_list: %s"%str(len(file_list)))
     #self.liststore.clear()
     #self.fill_liststore(file_list)
     #self.loading_spin.start()
     #self.loading_spin.show_all()
     self.spinn = SpinnerDialog(self)
     self.spinn.show()
     file_list = []
     pix_list = self.get_pix_list(file_list)
     self.fill_liststore(pix_list)
예제 #19
0
 def on_click_refresh_clicked(self, *arg):
     utils.async_call(self.download_vcodeimg,
                      self.url,
                      self.vcodefile,
                      callback=self.show_vcode)
예제 #20
0
	def on_click_refresh_clicked(self,*arg):
		utils.async_call(self.download_vcodeimg,self.url,self.vcodefile,
						 callback=self.show_vcode)
예제 #21
0
	def on_add_magnet_or_ed2k_link_file_button_clicked(self,*arg):
		dialog = Gtk.FileChooserDialog("Please choose a file", self,
			Gtk.FileChooserAction.OPEN,
			(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
			 Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

		response = dialog.run()
		if response == Gtk.ResponseType.OK:
			#linkfile = dialog.get_file().read()
			filename = dialog.get_filename()
			
			print("Open clicked")
			print("File selected: " + dialog.get_filename())
		elif response == Gtk.ResponseType.CANCEL:
			return
		
		dialog.destroy()
		
		link_list = open(filename).read()
		task_list = []
		invalid_list = []
		for line in link_list.split("\n"):
			line = line.strip()
			if line and ( line.startswith("magnet:?xt=urn") or \
				 line.startswith("ed2k://") ):
				task_list.append(line)
				
			elif line:
				invalid_list.append(line)
		if invalid_list:
				dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
						Gtk.ButtonsType.OK, "Attention")
				dialog.format_secondary_text(
						"Only magnet or ed2k protocal is support! Invalid lines :%s"%str(invalid_list))
				response = dialog.run()
				dialog.destroy()
				return 
		print(self.save_path)
		
		maglist = [ i['source_url'] for i in self.task_list   if "magnet:?xt=urn:" in i['source_url'] ]
		logger.debug("maglist: %s "%str(maglist))
		
		for i,l in enumerate(task_list):
			mag = re.search('(&.*$)',l).group(1)
			task_name = dict(urllib.parse.parse_qsl(mag))['dn']
			txt = "%s out of %s | %s is running."%(str(i),len(task_list),str(task_name))
			logger.info(txt)
			self.info_label.set_text(txt)
			maglink = re.search("(magnet[^&]*)",l).group(1)
			logger.debug("maglink: %s "%maglink)
			self.spinn = SpinnerDialog(self)
			self.spinn.show()
			if maglink not in maglist:
				
				self.info_label.set_text("Adding task: %s "%task_name)
				taskjson = cloudapi.add_task(self.bdstoken, l,self.save_path,self)
				self.init_view(self.bdstoken)
				self.spinn.destroy()

				#taskjson = cloudapi.add_task(l,self.save_path)
				logger.debug("taskjson: %s "%taskjson)
				if 'task_id' in taskjson.keys():
					self.spinn = SpinnerDialog(self)
					self.spinn.show()
					self.info_label.set_text("Querying task: %s "%task_name)
					task_id = str(taskjson['task_id'])
					utils.async_call(cloudapi.query_task, self.bdstoken,task_id,
							 callback=self.after_query_task)
					self.spinn.destroy()
				else:
					error = taskjson['error_msg']
					logger.info(error)
					self.info_label.set_text(error)
					#self.spinn.destroy()
				
			else:
				info = "Already existed,pass"
				logger.info(info)
				self.info_label.set_text(info)
			
				self.spinn.destroy()
예제 #22
0
	def after_get_token(self,token,error):

			self.token = token
			self.info_label.set_text("Geting public key")
			utils.async_call(auth.get_public_key,self.token,
							 callback=self.after_get_public_key)
예제 #23
0
    def get_pix_list(self, file_list):
        current_list = []

        def advance_frame(*user_data):

            num, pixiter = user_data
            #pass#
            if pixiter.advance() and not self.stop_gif:

                pix = pixiter.get_pixbuf()

                path = Gtk.TreePath(int(num))

                if len(self.liststore) > 0:

                    treeiter = self.liststore.get_iter(path)
                    self.liststore.set_value(treeiter, 1, pix)
                return True
            else:
                return False

        def down_img(num, thumbimg, link, fsid, header, path):
            logger.debug(" %s is downloading" % str(fsid))
            f = open(thumbimg, "wb")
            img = fetch(link, {}, fsid, header, path)
            f.write(img)
            f.close()
            return (num, thumbimg)

        def create_img_pix(thumbimg):
            if not GdkPixbuf.Pixbuf.get_file_info(thumbimg)[0]:
                return None
            else:
                return GdkPixbuf.Pixbuf.new_from_file(thumbimg)

        for row in file_list:
            #if cate == 1:
            #(num,thumb,filename,size,path,isdir,fsid,cate)
            num = row[0]
            thumb = row[1]
            path = row[4]
            isdir = row[5]
            fsid = row[6]
            cate = row[7]
            host = urlparse(thumb)[1]

            header = {
                'Host': host,
                'Referer': DISK_HOME,
            }
            if not os.path.exists("image"):
                os.makedirs("image")
            thumbimg = "image/" + fsid + ".jpg"

            if GdkPixbuf.Pixbuf.get_file_info(thumbimg)[0]:

                pix = GdkPixbuf.Pixbuf.new_from_file(thumbimg)

            elif thumb:
                self.stop_gif = False
                pixan = GdkPixbuf.PixbufAnimation.new_from_file(
                    "image/loading.gif")
                pixiter = pixan.get_iter()
                pix = pixiter.get_pixbuf()
                #pix.set_loop(True)
                GLib.timeout_add(pixiter.get_delay_time(), advance_frame, num,
                                 pixiter)
                logger.debug("Async call download for file %s " % str(fsid))
                utils.async_call(down_img,
                                 num,
                                 thumbimg,
                                 thumb,
                                 fsid,
                                 header,
                                 path,
                                 callback=self.reload_pix)
            elif isdir:
                pix = GdkPixbuf.Pixbuf.new_from_file("image/folder.png")
            else:
                pix = None
            rowlist = list(row)
            rowlist[1] = pix
            #elif cate == 6:
            #	pix = create_img_pix("image/folder.png")
            current_list.append(
                tuple(rowlist) + (SAVINGPATH, "0B", 0, "pending"))
        return current_list
예제 #24
0
	def init_view(self,bdstoken):
		
		utils.async_call(cloudapi.list_task, bdstoken,
				     callback=self.populate_view)

		self.fill_liststore([])
예제 #25
0
	def get_pix_list(self,file_list):
		current_list = []
		def advance_frame(*user_data):
		
			num,pixiter = user_data
			#pass#
			if pixiter.advance() and not self.stop_gif:
			
				pix = pixiter.get_pixbuf()
			
				path = Gtk.TreePath(int(num))
			
				if len(self.liststore) > 0:
			
					treeiter = self.liststore.get_iter(path)
					self.liststore.set_value(treeiter, 1, pix)
				return True
			else:
				return False
		def down_img(num,thumbimg,link,fsid,header,path):
			logger.debug(" %s is downloading"%str(fsid))
			f=open(thumbimg,"wb")
			img = fetch(link,{},fsid,header,path)
			f.write(img)
			f.close()
			return (num,thumbimg)
		def create_img_pix(thumbimg):
			if not GdkPixbuf.Pixbuf.get_file_info(thumbimg)[0]:
				return None
			else:
				return GdkPixbuf.Pixbuf.new_from_file(thumbimg)

		for row in file_list:
			#if cate == 1:
			#(num,thumb,filename,size,path,isdir,fsid,cate)
			num = row[0]
			thumb = row[1]
			path = row[4]
			isdir =row[5]
			fsid = row[6] 
			cate = row[7]
			host = urlparse(thumb)[1]

			header = {
			'Host':host,
			'Referer':DISK_HOME,
			}
			if not os.path.exists("image"):
					os.makedirs("image")
			thumbimg = "image/" + fsid + ".jpg"

			if GdkPixbuf.Pixbuf.get_file_info(thumbimg)[0]:

				pix = GdkPixbuf.Pixbuf.new_from_file(thumbimg)

			elif thumb:
				self.stop_gif = False
				pixan = GdkPixbuf.PixbufAnimation.new_from_file("image/loading.gif")
				pixiter = pixan.get_iter()
				pix = pixiter.get_pixbuf()
				#pix.set_loop(True)
				GLib.timeout_add(pixiter.get_delay_time(),
								 advance_frame,num,pixiter)
				logger.debug("Async call download for file %s "%str(fsid))
				utils.async_call(down_img, num,thumbimg,thumb,fsid,header,path,
				     callback=self.reload_pix)
			elif isdir:
				pix = GdkPixbuf.Pixbuf.new_from_file("image/folder.png")
			else:
				pix = None
			rowlist = list(row)
			rowlist[1] = pix
			#elif cate == 6:
			#	pix = create_img_pix("image/folder.png")
			current_list.append( tuple(rowlist) + (SAVINGPATH,"0B",0,"pending"))
		return current_list