def getInfoFile(parent, fname): fullPath = parent.dirPath + '/' + fname out = subprocess.Popen(['stat', fullPath], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() res = stdout.decode("utf-8") attrs = res.split() permission = attrs[2] fileNode = int(attrs[3]) fileOwner = attrs[4] groupOwner = attrs[5] fileSize = int(attrs[7]) t = fname.split('.') type = 'hidden' if len(t) > 1 and len(t[0]) > 0: type = t[-1] date = formatDate(res) file = File(parent.dirId, fname, permission, fileOwner, groupOwner, type, fileSize, fileNode, date, fullPath) try: f = open(fullPath, "rb") content = f.read() file.content = content except: return None return file
def getFileInfo(path): files = [] dirHash = hashlib.md5(path.encode()).hexdigest() connection = connect() try: with connection.cursor() as cursor: sql = 'SELECT * FROM File WHERE fId LIKE %s' cursor.execute(sql, (dirHash + '%', )) results = cursor.fetchall() for r in results: file = File('', r['fname'], r['permission'], r['fileOwner'], r['groupOwner'], r['fileType'], r['fileSize'], r['fileNode'], r['lastModified'], r['filePath']) file.content = r['content'] files.append(file) finally: connection.close() return files