def status(self): self.node.lock.acquire() port = self.node.address[1] n_peers = len(self.node.peers) n_bytes = self.node.network_usage self.node.lock.release() self.file_server.lock.acquire() n_files = len(self.file_server.paths) self.file_server.lock.release() status = _("Circle daemon running on port %d:\n") % port if self.config.get("public_dir"): status += _(" Public directory: ") + self.config["public_dir"] + "\n" else: status += _(" No public directory\n") if self.config.get("publish_apt"): status += _(" Apt cache published if available\n") else: status += _(" Apt cache not published\n") status += ( _(" %d files published (this may take a while to update)\n") % n_files + _(" Connected to %d peers, ") % n_peers + _("hashtable is %s\n") % (("inactive", "active (%d links)" % len(self.node.links))[self.node.hashtable_running]) + _(" Total network usage %s\n") % utility.human_size(n_bytes) ) if self.http_running: # import circle_http status = status + circle_http.status() return status
def get_text(self): return self.title + ' (%s) ' % utility.human_size(self.item['length'])
def __init__(self, filename, image, parent=None): super(DigestWidget, self).__init__(parent) table = [] file_info = QFileInfo(filename) table.append( [self.tr('File'), self.tr('File name'), file_info.fileName()]) table.append([ None, self.tr('Parent folder'), str(file_info.dir().absolutePath()) ]) table.append( [None, self.tr('MIME type'), magic.from_file(filename, mime=True)]) table.append([ None, self.tr('File size'), '{} bytes ({})'.format(QLocale().toString(file_info.size()), human_size(file_info.size())) ]) table.append([None, self.tr('File owner'), file_info.owner()]) table.append([ None, self.tr('Permissions'), str(oct(os.stat(filename).st_mode)[-3:]) ]) table.append([ None, self.tr('Creation time'), file_info.birthTime().toLocalTime().toString() ]) table.append([ None, self.tr('Last access'), file_info.lastRead().toLocalTime().toString() ]) table.append([ None, self.tr('Last modified'), file_info.lastModified().toLocalTime().toString() ]) table.append([ None, self.tr('Metadata changed'), file_info.metadataChangeTime().toLocalTime().toString() ]) file = QFile(filename) if not file.open(QIODevice.ReadOnly): QMessageBox.warning(self, self.tr('Warning'), self.tr('Unable to read file from disk!')) return data = file.readAll() md5 = QCryptographicHash.hash(data, QCryptographicHash.Md5).toHex() table.append([ self.tr('CryptoHash'), self.tr('MD5'), str(md5, encoding='utf-8') ]) sha1 = QCryptographicHash.hash(data, QCryptographicHash.Sha1).toHex() table.append([None, self.tr('SHA2-1'), str(sha1, encoding='utf-8')]) sha224 = QCryptographicHash.hash(data, QCryptographicHash.Sha224).toHex() table.append( [None, self.tr('SHA2-224'), str(sha224, encoding='utf-8')]) sha256 = QCryptographicHash.hash(data, QCryptographicHash.Sha256).toHex() table.append( [None, self.tr('SHA2-256'), str(sha256, encoding='utf-8')]) sha384 = QCryptographicHash.hash(data, QCryptographicHash.Sha384).toHex() table.append( [None, self.tr('SHA2-384'), str(sha384, encoding='utf-8')]) sha512 = QCryptographicHash.hash(data, QCryptographicHash.Sha512).toHex() table.append( [None, self.tr('SHA2-512'), str(sha512, encoding='utf-8')]) sha3_224 = QCryptographicHash.hash( data, QCryptographicHash.Sha3_224).toHex() table.append( [None, self.tr('SHA3-224'), str(sha3_224, encoding='utf-8')]) sha3_256 = QCryptographicHash.hash( data, QCryptographicHash.Sha3_256).toHex() table.append( [None, self.tr('SHA3-256'), str(sha3_256, encoding='utf-8')]) sha3_384 = QCryptographicHash.hash( data, QCryptographicHash.Sha3_384).toHex() table.append( [None, self.tr('SHA3-384'), str(sha3_384, encoding='utf-8')]) sha3_512 = QCryptographicHash.hash( data, QCryptographicHash.Sha3_512).toHex() table.append( [None, self.tr('SHA3-512'), str(sha3_512, encoding='utf-8')]) table.append([ self.tr('ImageHash'), self.tr('Average'), str(cv.img_hash.averageHash(image)[0]) ]) # table_widget.item(15, 0).setToolTip(self.tr('Average hash')) table.append([ None, self.tr('Block mean'), str(cv.img_hash.blockMeanHash(image)[0]) ]) # table_widget.item(16, 0).setToolTip(self.tr('Block mean hash')) table.append([ None, self.tr('Color moments'), str(cv.img_hash.colorMomentHash(image)[0]) ]) # table_widget.item(17, 0).setToolTip(self.tr('Color moments hash')) table.append([ None, self.tr('Marr-Hildreth'), str(cv.img_hash.marrHildrethHash(image)[0]) ]) # table_widget.item(18, 0).setToolTip(self.tr('Marr-Hildreth hash')) table.append( [None, self.tr('Perceptual'), str(cv.img_hash.pHash(image)[0])]) # table_widget.item(19, 0).setToolTip(self.tr('Perceptual hash')) table.append([ None, self.tr('Radial variance'), str(cv.img_hash.radialVarianceHash(image)[0]) ]) # table_widget.item(20, 0).setToolTip(self.tr('Radial variance hash')) headers = [self.tr('Group'), self.tr('Property'), self.tr('Value')] table_widget = TableWidget(table, headers) main_layout = QVBoxLayout() main_layout.addWidget(table_widget) self.setLayout(main_layout) self.setMinimumSize(620, 520)
def search_task(daemon, query, input, output, connection): for char in "+-_.,?()![]": query = query.replace(char, " ") query = query.lower() list = query.split() if list: key = list[0] else: key = "" if key.__len__() < 3: output.write("Keyword %s too short: must be at least 3 characters" % key) input.close() output.close() connection.close() return pipe = daemon.node.retrieve(hash.hash_of(key)) results = [] restricted = 0 while not pipe.finished() and not restricted: for item in pipe.read_all(): if results.__len__() == 100: restricted = 1 break if item[1]["name"] not in results: results.append(item[1]["name"]) filename = utility.force_string(item[1]["filename"]) extension = string.split(string.split(filename, ".")[-1], "-")[0] lext = string.lower(extension) if lext in ["mp3", "ogg"]: music = 1 else: music = 0 if item[1].has_key("music_title"): ref = utility.force_string(item[1]["music_title"]) if ref.strip() == "": ref = filename else: ref = utility.force_string(item[1]["filename"]) length = item[1].get("length") if not length: sl = "" else: sl = utility.human_size(length) output.write(hash.hash_to_url(item[1]["name"]) + " \t" + sl + " \t" + filename + "\n") time.sleep(0.5) try: output.flush() except: return if not results: try: output.write('No document matching "' + key + '"') except: pass else: if results.__len__() == 1: msg = "1 file found." else: msg = "%d files found." % results.__len__() output.write(msg) pipe.stop() try: input.close() output.close() connection.close() except: pass