예제 #1
0
	def Seal(dir_path):
		"""
Seal a folder: count recursively MD5 checksum, write it to all.md5, then make the folder read-only.
Shell function, need package md5deep.
"""
		METHOD_NAME = f"Blister.Seal"
		qdir = QDir(dir_path)
		if not qdir.exists():
			print(f"{METHOD_NAME}: Path doesn't exist or isn't a dir.", end='\n')
			return False
		qfiles = QFileInfo(qdir, "**/*")
		file_list = glob.glob(qfiles.absoluteFilePath(), recursive=True)
		for _file in file_list:
			fileinfo = QFileInfo(_file)
			if not fileinfo.isReadable():
				print(f"{METHOD_NAME}: There is input cannot be checked (unreadable files). Stopped.", end='\n')
				return False
		start_time = time.time()
		sp = subprocess.Popen(f"cd {qdir.absolutePath()}; (md5deep -lr * > all.md5); chmod 555 -R {qdir.absolutePath()}", shell=True, stderr=subprocess.PIPE)
		out, err = sp.communicate()
		if err != b'':
			print(f"{METHOD_NAME}: Shell error: {str(err)}", end='\n')
			return False
		print(f"{METHOD_NAME}: Dir was sealed [%s]:\n\t{qdir.absolutePath()}" % (Blister.SecToTime(time.time() - start_time)), end='\n')
		return True
예제 #2
0
파일: settings.py 프로젝트: opt9/ninja-ide
def detect_python_path():
    if (IS_WINDOWS and PYTHON_EXEC_CONFIGURED_BY_USER) or not IS_WINDOWS:
        return []

    suggested = []
    dirs = []
    try:
        drives = [
            QDir.toNativeSeparators(d.absolutePath()) for d in QDir.drives()
        ]

        for drive in drives:
            info = QFileInfo(drive)
            if info.isReadable():
                dirs += [
                    os.path.join(drive, folder) for folder in os.listdir(drive)
                ]
        for folder in dirs:
            file_path = os.path.join(folder, "python.exe")
            if ("python" in folder.lower()) and os.path.exists(file_path):
                suggested.append(file_path)
    except:
        print("Detection couldnt be executed")
    finally:
        return suggested
예제 #3
0
	def Input(filenames):
		"""
Take list of masks or filenames, return list of absolute filepaths, or False if error.
"""
		METHOD_NAME = f"Blister.Input"
		if type(filenames) != type(list()):
			print(f"{METHOD_NAME}: Invalid input type {type(filenames)}. List of strings only.", end='\n')
			return False
		file_list = []
		fileinfo_list = []
		fileinfo_unreadable = []
		for filename in filenames:
			if type(filename) != type(str()):
				print(f"{METHOD_NAME}: Invalid input type {type(filename)} in list. Strings only.", end='\n')
				return False
			file_list += glob.glob(QFileInfo(filename).absoluteFilePath())
		file_list = list(set(file_list))
		file_list.sort()
		for _file in file_list:
			fileinfo = QFileInfo(_file)
			if fileinfo.isFile():
				if fileinfo.isReadable():
					fileinfo_list += [fileinfo.absoluteFilePath()]
				else:
					fileinfo_unreadable += [fileinfo.absoluteFilePath()]
		if fileinfo_unreadable:
			print(f"{METHOD_NAME}: List of unreadable files (will not be processed):", end='\n')
			for fileinfo in fileinfo_unreadable: print(f"\t{fileinfo}", end='\n')
		if not fileinfo_list:
			print(f"{METHOD_NAME}: No input files exist or reachable.", end='\n')
			return False
		print(f"{METHOD_NAME}: List of input files:", end='\n')
		for fileinfo in fileinfo_list: print(f"\t{fileinfo}", end='\n')
		return fileinfo_list
예제 #4
0
    def ClickedEvent(self, event):
        validSuffix = ['jpg', 'png']
        index = self.selectedIndexes()[0]
        finfo = QFileInfo(self._model.filePath(index))

        if finfo.suffix().lower() not in validSuffix:
            return

        if finfo.isFile() and finfo.isReadable():
            self.fileSelected.emit(finfo.absoluteFilePath())
예제 #5
0
    def read_BAT(self):
        current_charge = None
        full_capacity = None

        file_BAT0_current = "/sys/class/power_supply/BAT0/charge_now"
        file_info = QFileInfo(file_BAT0_current)
        if file_info.isFile() and file_info.isReadable():
            with open(file_BAT0_current) as bat_file:
                current_charge = bat_file.readline()

        file_BAT0_capacity = "/sys/class/power_supply/BAT0/charge_full"
        file_info_current = QFileInfo(file_BAT0_capacity)
        if file_info_current.isFile() and file_info_current.isReadable():
            with open(file_BAT0_capacity) as bat_file:
                full_capacity = bat_file.readline()

        if current_charge is not None and full_capacity is not None:
            print("FULL: ", current_charge)
            print("FULL: ", full_capacity)

            bat_percentage = int(current_charge) // int(full_capacity)
            print("Percentage: ", (bat_percentage)*100)
예제 #6
0
def getMetadataForFileList(filenames):
    '''Takes a list of filenames, returns a list of metadata associated with
    all files in that list that are readable tracks'''

    metadata = []
    for filename in filenames:
        info = QFileInfo(filename)
        if info.isDir() and info.isExecutable():
            print(filename)
            dir = QDir(filename)
            print(dir.entryList(QDir.AllEntries | QDir.NoDotAndDotDot))
            metadata.extend(
                getMetadataForFileList([
                    i.filePath()
                    for i in dir.entryInfoList(QDir.AllEntries
                                               | QDir.NoDotAndDotDot)
                ]))
        elif info.isFile() and info.isReadable():
            print(filename)
            metadata.extend(processFile(filename))
    return metadata
예제 #7
0
 def createRequest(self, op, request, outgoingData=None):
     """
     Public method to create a request.
     
     @param op the operation to be performed
         (QNetworkAccessManager.Operation)
     @param request reference to the request object (QNetworkRequest)
     @param outgoingData reference to an IODevice containing data to be sent
         (QIODevice)
     @return reference to the created reply object (QNetworkReply)
     """
     if op == QNetworkAccessManager.GetOperation:
         fileInfo = QFileInfo(request.url().toLocalFile())
         if not fileInfo.isDir() or \
            not fileInfo.isReadable() or \
            not fileInfo.exists():
             return None
         from .FileReply import FileReply
         return FileReply(request.url(), self.parent())
     else:
         return None
예제 #8
0
 def createRequest(self, op, request, outgoingData=None):
     """
     Public method to create a request.
     
     @param op the operation to be performed
         (QNetworkAccessManager.Operation)
     @param request reference to the request object (QNetworkRequest)
     @param outgoingData reference to an IODevice containing data to be sent
         (QIODevice)
     @return reference to the created reply object (QNetworkReply)
     """
     if op == QNetworkAccessManager.GetOperation:
         fileInfo = QFileInfo(request.url().toLocalFile())
         if not fileInfo.isDir() or \
            not fileInfo.isReadable() or \
            not fileInfo.exists():
             return None
         from .FileReply import FileReply
         return FileReply(request.url(), self.parent())
     else:
         return None
예제 #9
0
def detect_python_path():
    if (IS_WINDOWS and PYTHON_PATH_CONFIGURED_BY_USER) or not IS_WINDOWS:
        return []

    suggested = []
    try:
        drives = [QDir.toNativeSeparators(d.absolutePath())
                  for d in QDir.drives()]
        dirs = []
        for drive in drives:
            info = QFileInfo(drive)
            if info.isReadable():
                dirs += [os.path.join(drive, folder)
                         for folder in os.listdir(drive)]
        for folder in dirs:
            file_path = os.path.join(folder, "python.exe")
            if ("Python" in folder) and os.path.exists(file_path):
                suggested.append(file_path)
    except:
        print("Detection couldnt be executed")

    return suggested