Esempio n. 1
0
def progress_callback(total_downloaded, total_size):
    global progress_dialog
    if progress_dialog == None:
        progress_dialog = create_progress_dialog()
        progress_dialog.Show()
    if total_downloaded == total_size:
        progress_dialog.Destroy()
    else:
        progress_dialog.Update((total_downloaded * 100) / total_size,
                               _(u"Updating... %s of %s") %
                               (str(utils.convert_bytes(total_downloaded)),
                                str(utils.convert_bytes(total_size))))
Esempio n. 2
0
 async def stats(self, ctx):
     utils.log(ctx)
     uname = platform.uname()
     cputype = cpuinfo.get_cpu_info()["brand_raw"]
     osversion = uname.version
     ostype = uname.system
     uptime = time.time() - starttime
     if psutilinstalled:
         cores = psutil.cpu_count(logical=True)
         cpuuse = psutil.cpu_percent()
         svmem = psutil.virtual_memory()
         mem = utils.convert_bytes(svmem.total)
         used = utils.convert_bytes(svmem.used)
         percent = svmem.percent
         partition = psutil.disk_partitions()[0]
         partition_usage = psutil.disk_usage(partition.mountpoint)
         disk_total = utils.convert_bytes(partition_usage.total)
         disk_used = utils.convert_bytes(partition_usage.used)
         disk_percent = partition_usage.percent
     embed = discord.Embed(title="Stats",
                           description="System stats",
                           color=0x1E00FF)
     embed.add_field(
         name="Uptime",
         value=f"{humanfriendly.format_timespan(uptime)}",
         inline=False,
     )
     embed.add_field(
         name="CPU",
         value=
         f"{cputype} {f'({cores} cores)' if psutilinstalled == True else ''}",
         inline=False,
     )
     if psutilinstalled:
         embed.add_field(name="CPU Usage", value=f"{cpuuse}%", inline=False)
         embed.add_field(name="OS",
                         value=f"{ostype} ({osversion})",
                         inline=False)
         embed.add_field(name="Memory", value=f"{mem}", inline=False)
         embed.add_field(name="Used",
                         value=f"{used} ({percent}%)",
                         inline=False)
         embed.add_field(name="Disk Total",
                         value=f"{disk_total}",
                         inline=False)
         embed.add_field(name="Disk Used",
                         value=f"{disk_used} ({disk_percent}%)",
                         inline=False)
     await ctx.send(embed=embed)
Esempio n. 3
0
 def update_file_status(self):
     total_size = file_count = 0
     
     iter = QtGui.QTreeWidgetItemIterator(self.ui.treeWidgetFiles)
     while iter.value(): 
         file_count += 1
         total_size += iter.value().attachment.size
         iter += 1
         
     self.ui.tabWidget.setTabText(1, "Files (%s)" % (file_count))
     self.ui.statusbar.showMessage("%s files loaded (%s)" % (file_count, convert_bytes(total_size)))
Esempio n. 4
0
    def update_file_status(self):
        total_size = file_count = 0

        iter = QtGui.QTreeWidgetItemIterator(self.ui.treeWidgetFiles)
        while iter.value():
            file_count += 1
            total_size += iter.value().attachment.size
            iter += 1

        self.ui.tabWidget.setTabText(1, "Files (%s)" % (file_count))
        self.ui.statusbar.showMessage("%s files loaded (%s)" %
                                      (file_count, convert_bytes(total_size)))
Esempio n. 5
0
 def progress_callback(self, monitor):
  progress = {}
  progress["total"] = monitor.len
  progress["current"] = monitor.bytes_read
  if progress["current"] == 0:
   progress["percent"] = 0
   self.transfer_rate = 0
  else:
   progress["percent"] = int((float(progress["current"]) / progress["total"]) * 100)
   self.transfer_rate = progress["current"] / self.elapsed_time()
  progress["speed"] = '%s/s' % convert_bytes(self.transfer_rate)
  if self.transfer_rate:
   progress["eta"] = (progress["total"] - progress["current"]) / self.transfer_rate
  else:
   progress["eta"] = 0
  pub.sendMessage("uploading", data=progress)
Esempio n. 6
0
async def main():
    async with aiohttp.ClientSession(json_serialize=ujson.dumps, headers={'Connection': 'keep-alive'}) as session:
        async with session.get(
                f"https://api.telegra.ph/getPage/{parser.parse_args().link.removeprefix('https://telegra.ph/')}",
                params={'return_content': 'true'}
        ) as response:
            response = await response.json()

            old_size = getsize(parser.parse_args().folder)['raw']
            start_time = datetime.now()
            log([
                f"[info] Started at: {datetime.now()}",
                f"[download] {response['result']['title']}",
            ])

            queue = response['result']['content']
            files = []

            while queue:
                curr = queue.pop()

                if "children" in curr and (nexts := curr["children"]) and isinstance(nexts, list):
                    queue.extend(nexts)

                if isinstance(curr, dict) and (curr["tag"] == "img" or curr["tag"] == "video"):
                    files.append(curr['attrs']['src'])

            urls = [filename.split('/')[-1] for filename in files[::-1]]
            log(f"[info] Files in telegraph page: {len(urls)}")

            await asyncio.gather(*[download_file(
                url,
                parser.parse_args().folder,
                file_id
            ) for file_id, url in enumerate(urls)])

            size = convert_bytes(getsize(parser.parse_args().folder)['raw'] - old_size)
            log([
                f"[download] Saved {size} to \"{parser.parse_args().folder}\"",
                f"[info] Time elapsed: {datetime.now() - start_time}"
            ])
Esempio n. 7
0
 def add_files(self, filenames):
     for filename in filenames:
         if not os.path.exists(filename) or not os.path.isfile(filename):
             # file not found, skip
             continue
         
         attachment = KurirAttachment(unicode(filename))
         
         twi = QtGui.QTreeWidgetItem()
         twi.attachment = attachment
         twi.setText(0, attachment.name)
         twi.setToolTip(0, attachment.path)
         twi.setText(1, convert_bytes(attachment.size))
         twi.setToolTip(1, "%s bytes" % attachment.size)
         
         icon = QtGui.QIcon()
         icon.addPixmap(QtGui.QPixmap(":/kurir/%s" % (get_file_icon(attachment.name))), QtGui.QIcon.Normal, QtGui.QIcon.Off)
         twi.setIcon(0, icon)            
         
         self.ui.treeWidgetFiles.addTopLevelItem(twi)
         
     self.emit(QtCore.SIGNAL("file_list_changed"))
Esempio n. 8
0
    def transfer_progress(self, timestamp, progress, total):
        print "send progress", timestamp, progress, total
        self.history.append((timestamp, progress))

        # calculate speed
        history = self.history[-500:]
        time_diff = history[-1][0] - history[0][0]
        progress_diff = history[-1][1] - history[0][1]
        if progress == total:
            self.history = []

        print "timediff", time_diff, progress_diff

        if time_diff:
            speed = progress_diff / time_diff
        else:
            speed = progress_diff

        #        self.ui.labelTransfer.setText("Transferred %s of %s (%s/s)" % (convert_bytes(progress), convert_bytes(total), convert_bytes(speed)))
        self.ui.progressTransfer.setMaximum(total)
        self.ui.progressTransfer.setValue(progress)
        self.setWindowTitle("%s/s" % (convert_bytes(speed)))
Esempio n. 9
0
    def transfer_progress(self, timestamp, progress, total):
        print "send progress", timestamp, progress, total
        self.history.append((timestamp, progress))

        # calculate speed
        history = self.history[-500:]
        time_diff = history[-1][0] - history[0][0]
        progress_diff = history[-1][1] - history[0][1]
        if progress == total:
            self.history = []

        print "timediff", time_diff, progress_diff

        if time_diff:
            speed = progress_diff / time_diff
        else:
            speed = progress_diff

#        self.ui.labelTransfer.setText("Transferred %s of %s (%s/s)" % (convert_bytes(progress), convert_bytes(total), convert_bytes(speed)))
        self.ui.progressTransfer.setMaximum(total)
        self.ui.progressTransfer.setValue(progress)
        self.setWindowTitle("%s/s" % (convert_bytes(speed)))
Esempio n. 10
0
    def add_files(self, filenames):
        for filename in filenames:
            if not os.path.exists(filename) or not os.path.isfile(filename):
                # file not found, skip
                continue

            attachment = KurirAttachment(unicode(filename))

            twi = QtGui.QTreeWidgetItem()
            twi.attachment = attachment
            twi.setText(0, attachment.name)
            twi.setToolTip(0, attachment.path)
            twi.setText(1, convert_bytes(attachment.size))
            twi.setToolTip(1, "%s bytes" % attachment.size)

            icon = QtGui.QIcon()
            icon.addPixmap(
                QtGui.QPixmap(":/kurir/%s" % (get_file_icon(attachment.name))),
                QtGui.QIcon.Normal, QtGui.QIcon.Off)
            twi.setIcon(0, icon)

            self.ui.treeWidgetFiles.addTopLevelItem(twi)

        self.emit(QtCore.SIGNAL("file_list_changed"))
Esempio n. 11
0
def progress_callback(total_downloaded, total_size):
	global progress_dialog
	if progress_dialog == None:
		progress_dialog = create_progress_dialog()
		progress_dialog.Show()
	if total_downloaded == total_size:
		progress_dialog.Destroy()
	else:
		progress_dialog.Update((total_downloaded*100)/total_size, _(u"Updating... %s of %s") % (str(utils.convert_bytes(total_downloaded)), str(utils.convert_bytes(total_size))))
Esempio n. 12
0
 #                      tfail=num_files_fail,
 #                      tori=utils.convert_bytes(total_size_bytes),
 #                     tcompact=utils.convert_bytes(os.path.getsize(utils.get_zip_file_name())),
 #                      tavail=utils.get_free_space(config.TARGET_BKP_DIR),
 #                      fbkp_name=utils.get_zip_file_name().,
 #                      cpori=config.CP_ORIGEM,
 #                      cpdest=config.CP_DESTINO)
 print 'ptm='+config.PTM_NAME
 print 'data='+inicio.date().strftime("%d/%m/%Y")
 print 'inicio='+inicio.time().strftime("%H:%M:%S")
 print 'fim='+fim.time().strftime("%H:%M:%S")
 print 'tempo='+str(fim-inicio)
 print 'tfiles='+str(num_files_total)
 print 'tfcopied='+str(num_files_ok)
 print 'tfail='+str(num_files_fail)
 print 'tori='+str(utils.convert_bytes(total_size_bytes))
 print 'tcompact='+str(utils.convert_bytes(os.path.getsize(utils.get_zip_file_name() ) ) )
 print 'tavail='+str(utils.get_free_space(config.TARGET_BKP_DIR))
 print 'fbkp_name='+utils.get_zip_file_name()
 print 'cpori='+config.CP_ORIGEM
 print 'cpdest='+config.CP_DESTINO
 
          
 msg = []
 msg.append('PTM:'+config.PTM_NAME)
 
 msg.append(u'Data:'+inicio.date().strftime("%d/%m/%Y"))
 msg.append(u'Hora de Início:'+inicio.time().strftime("%H:%M:%S"))
 msg.append(u'Hora de Término:'+fim.time().strftime("%H:%M:%S"))
 msg.append(u'Tempo do Backup:'+str(fim-inicio))
 msg.append(u'Número Total de arquivos:'+str(num_files_total))