Skip to content

Commit

Permalink
order hits
Browse files Browse the repository at this point in the history
  • Loading branch information
ngawangtrinley committed Apr 7, 2018
1 parent 32b7126 commit 85af7d5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
First version of an archive auditing tool for BDRC

## Get the standalone desktop app
* Mac - [bdrc-audit01](https://github.com/ngawangtrinley/bdrc-audit/releases/download/v01/bdrc-audit.zip)
* Mac - [bdrc-audit01](https://github.com/ngawangtrinley/bdrc-audit/releases/download/v01/bdrc-audit.zip) (zip)
* Windows - coming soon
* Linux - coming soon

Expand Down
70 changes: 32 additions & 38 deletions bdrc-audit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python

import os, glob, sys
import os
import glob
import sys
from PyQt5.QtCore import (QDir, QDirIterator, QIODevice, QFile, QFileInfo, Qt, QTextStream,
QUrl)
from PyQt5.QtGui import QDesktopServices, QFont, QColor
Expand All @@ -9,6 +11,8 @@
QProgressDialog, QPushButton, QSizePolicy, QTableWidget, QCheckBox,
QTableWidgetItem, QSpinBox, QMessageBox)

from ext import count


class Window(QDialog):
def __init__(self, parent=None):
Expand All @@ -24,8 +28,8 @@ def __init__(self, parent=None):
# print(os.path.abspath(bundle_dir + "/../../"))

# Initialize user settings
self.recursivity = QDirIterator.Subdirectories
self.recursivity_2 = QDirIterator.NoIteratorFlags
self.searchRecursivity = QDirIterator.Subdirectories
self.countRecursivity = QDirIterator.NoIteratorFlags
self.dirFilters = (QDir.Dirs | QDir.NoDotAndDotDot)
# to swap size and count in file view
self.dirView = True
Expand All @@ -47,16 +51,16 @@ def __init__(self, parent=None):
self.typeComboBox.currentIndexChanged.connect(self.changeType)
self.checkBox = QCheckBox("Subfolders")
self.checkBox.toggle()
self.checkBox.stateChanged.connect(self.changeRecursivity)
self.checkBox.stateChanged.connect(self.changeSearchRecursivity)
self.findButton = self.createButton("&Find", self.find)

# Row 2

self.depthLabel = QLabel("Count files in subfolder number:")
self.depthLabel = QLabel("Count files in subfolder level")
self.folderDepthSpinBox = QSpinBox()
self.folderDepthSpinBox.valueChanged.connect(self.changeFolderDepth)
self.checkBox_2 = QCheckBox("Files in all subfolders")
self.checkBox_2.stateChanged.connect(self.changeRecursivity_2)
self.checkBox_2 = QCheckBox("Count all files")
self.checkBox_2.stateChanged.connect(self.changeCountRecursivity)

# Row 3 Table
self.createFilesTable()
Expand Down Expand Up @@ -103,11 +107,11 @@ def __init__(self, parent=None):
self.resize(520, 440)
# self.resize(442, 440)

def changeRecursivity_2(self, state):
def changeCountRecursivity(self, state):
if state == Qt.Checked:
self.recursivity_2 = QDirIterator.Subdirectories
self.countRecursivity = QDirIterator.Subdirectories
else:
self.recursivity_2 = QDirIterator.NoIteratorFlags
self.countRecursivity = QDirIterator.NoIteratorFlags

def changeFolderDepth(self, value):
self.subfolderLevel = value
Expand Down Expand Up @@ -138,11 +142,11 @@ def changeType(self, typeIndex):
self.depthLabel.hide()
self.folderDepthSpinBox.hide()

def changeRecursivity(self, state):
def changeSearchRecursivity(self, state):
if state == Qt.Checked:
self.recursivity = QDirIterator.Subdirectories
self.searchRecursivity = QDirIterator.Subdirectories
else:
self.recursivity = QDirIterator.NoIteratorFlags
self.searchRecursivity = QDirIterator.NoIteratorFlags

def browse(self):
directory = QFileDialog.getExistingDirectory(self, "Find files",
Expand Down Expand Up @@ -180,7 +184,7 @@ def find(self):
self.currentDir = QDir(self.path)

self.it = QDirIterator(self.path, fileName,
self.dirFilters, self.recursivity)
self.dirFilters, self.searchRecursivity)
while self.it.hasNext():
files.append(self.it.next())

Expand Down Expand Up @@ -233,7 +237,7 @@ def showFiles(self, files):
# print(QFileInfo(file).baseName)

if os.path.isdir(fn):
size = self.countFiles(fn)
size = count.countFiles(self, fn)
if self.dirView:
sizeItem = QTableWidgetItem("%d" % size)
else:
Expand All @@ -243,8 +247,12 @@ def showFiles(self, files):
sizeItem = QTableWidgetItem(
"%d KB" % (int((size + 1023) / 1024)))

head = '.'
if self.path.endswith('/'):
head = './'

fileNameItem = QTableWidgetItem(
self.pathToDisplay.replace(self.path, '.'))
self.pathToDisplay.replace(self.path, head))
fileNameItem.setFlags(fileNameItem.flags() ^ Qt.ItemIsEditable)

sizeItem.setTextAlignment(Qt.AlignVCenter | Qt.AlignRight)
Expand All @@ -261,27 +269,6 @@ def showFiles(self, files):
self.filesFoundLabel.setText(
"%d matches. Double click to open." % len(files))

def countFiles(self, folder):
files = []

if self.subfolderLevel > 0:
try:
path = glob.glob('%s/%s' %
(folder, '*/'*self.subfolderLevel))[0]
self.pathToDisplay = path
except:
return 0
else:
path = folder

it = QDirIterator(
path, (QDir.Files | QDir.NoSymLinks), self.recursivity_2)
while it.hasNext():
files.append(it.next())

count = len(files)
return count

def createButton(self, text, member):
button = QPushButton(text)
button.clicked.connect(member)
Expand All @@ -304,6 +291,9 @@ def createFilesTable(self):
self.filesTable.verticalHeader().hide()
self.filesTable.setShowGrid(False)

self.filesTable.setSortingEnabled(True)
self.filesTable.sortByColumn(0, Qt.AscendingOrder)

self.filesTable.cellActivated.connect(self.openFileOfItem)

def saveSheet(self):
Expand Down Expand Up @@ -331,7 +321,11 @@ def openFileOfItem(self, row, column):
item = self.filesTable.item(row, 0)

# Complete links to make them click
path = self.path + item.text()[1:]
tail = item.text()[1:]
if self.path.endswith('/'):
tail = item.text()[2:]
path = self.path + tail
print(path)
QDesktopServices.openUrl(QUrl.fromLocalFile(
self.currentDir.absoluteFilePath(path)))

Expand Down
24 changes: 24 additions & 0 deletions ext/count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

from PyQt5.QtCore import QDir, QDirIterator


def countFiles(self, folder):
files = []

if self.subfolderLevel > 0:
try:
path = glob.glob('%s/%s' %
(folder, '*/'*self.subfolderLevel))[0]
self.pathToDisplay = path
except:
return 0
else:
path = folder

it = QDirIterator(
path, (QDir.Files | QDir.NoSymLinks), self.countRecursivity)
while it.hasNext():
files.append(it.next())

count = len(files)
return count
14 changes: 14 additions & 0 deletions test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/Users/trinley/github/bdrc-audit/__pycache__,1
/Users/trinley/github/bdrc-audit/build,0
/Users/trinley/github/bdrc-audit/build/bdrc-audit,9
/Users/trinley/github/bdrc-audit/dist,2
/Users/trinley/github/bdrc-audit/dist/bdrc-audit.app,0
/Users/trinley/github/bdrc-audit/dist/bdrc-audit.app/Contents,1
/Users/trinley/github/bdrc-audit/dist/bdrc-audit.app/Contents/Frameworks,0
/Users/trinley/github/bdrc-audit/dist/bdrc-audit.app/Contents/MacOS,1
/Users/trinley/github/bdrc-audit/dist/bdrc-audit.app/Contents/Resources,1
/Users/trinley/github/bdrc-audit/ext,3
/Users/trinley/github/bdrc-audit/ext/__pycache__,6
/Users/trinley/github/bdrc-audit/rc,1
/Users/trinley/github/bdrc-audit/scripts,1
/Users/trinley/github/bdrc-audit/scripts/__pycache__,1

0 comments on commit 85af7d5

Please sign in to comment.