Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
58c2fe1
bring classifier up to speed with current tools
iwishiwasaneagle Mar 7, 2022
fde410c
Update CI.yml
iwishiwasaneagle Mar 7, 2022
01d9199
Update CI.yml
iwishiwasaneagle Mar 7, 2022
5765553
Update CI.yml
iwishiwasaneagle Mar 7, 2022
d63c908
Update CI.yml
iwishiwasaneagle Mar 7, 2022
bb9ebbf
move testing to pytest
iwishiwasaneagle Mar 7, 2022
bcced1a
Merge branch 'master' of github.com:iwishiwasaneagle/classifier
iwishiwasaneagle Mar 7, 2022
71d8942
make tox use default interpreter
iwishiwasaneagle Mar 7, 2022
f84d216
Update README.md
iwishiwasaneagle Mar 7, 2022
27e301d
try except for removing tests
iwishiwasaneagle Mar 7, 2022
17ae2e2
Merge branch 'master' of github.com:iwishiwasaneagle/classifier
iwishiwasaneagle Mar 7, 2022
d68a1e4
Merge branch 'master' of github.com:iwishiwasaneagle/classifier
iwishiwasaneagle Mar 7, 2022
cf8460e
Merge branch 'master' of github.com:iwishiwasaneagle/classifier
iwishiwasaneagle Mar 7, 2022
0a5b3c3
disable windows testing for now. needs someone on a windows machine t…
iwishiwasaneagle Mar 7, 2022
03f9eb3
change name for PyPi
iwishiwasaneagle Mar 7, 2022
9afc587
badges
iwishiwasaneagle Mar 7, 2022
939a7da
Create LICENSE
iwishiwasaneagle Mar 7, 2022
6f755be
Update README.md
iwishiwasaneagle Mar 7, 2022
0cda127
wasn't working due to import errors. works now
iwishiwasaneagle Mar 7, 2022
359a578
handle getting version from package rather than hard coding it
iwishiwasaneagle Mar 7, 2022
0430298
use name of the pypi package (i.e. the wheel) and not the local package
iwishiwasaneagle Mar 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches: [master, dev]
pull_request:
workflow_dispatch:

jobs:
run-tests:
runs-on: ${{matrix.platform}}
strategy:
matrix:
platform: [ubuntu-latest, macos-latest] # Enable `windows-latest` once someone on a windows machine can figure out why os.rename doesn't work
python-version: ["3.7", "3.8", "3.9"]
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v2
id: cache-tox-tests
with:
path: .tox
key: ${{ runner.os }}-${{ matrix.python-version }}-venv-${{ hashFiles('requirements.txt') }}-${{ hashFiles('tests/requirements.txt') }}-${{ hashFiles('setup.cfg') }}
restore-keys: |
${{ runner.os }}-tox-tests

- run: pip install tox

- name: Run tox
run: tox

- uses: codecov/[email protected]
if: ${{runner.os == 'Linux' && matrix.python-version == '3.9'}}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
fail_ci_if_error: true
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2015 Bhrigu Srivastava
Copyright (c) 2022 Jan-Hendrik Ewers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@

# Classifier

[![CI](https://github.com/iwishiwasaneagle/classifier/actions/workflows/CI.yml/badge.svg)](https://github.com/iwishiwasaneagle/classifier/actions/workflows/CI.yml)
[![codecov](https://codecov.io/gh/iwishiwasaneagle/classifier/branch/master/graph/badge.svg?token=ZW51EYKLL0)](https://codecov.io/gh/iwishiwasaneagle/classifier)
[![PyPI version](https://badge.fury.io/py/classifier-reborn.svg)](https://badge.fury.io/py/classifier-reborn)
[![GitHub](https://img.shields.io/github/license/iwishiwasaneagle/classifier)](https://github.com/iwishiwasaneagle/classifier/blob/master/LICENSE)


Organize files in your current directory, by classifying them into folders of music, pdfs, images, etc.

## Installation

```sh
$ pip install classifier
$ pip install classifier-reborn
```

#### Compatibility
* Python 2.7 / Python 3.4
* Python 3.7 - Python 3.9
* Linux / OSX / Windows


Expand Down
2 changes: 2 additions & 0 deletions classifier/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._version import __version__
from .classifier import main
14 changes: 14 additions & 0 deletions classifier/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

if sys.version_info[:2] >= (3, 8):
from importlib.metadata import PackageNotFoundError, version # pragma: no cover
else:
from importlib_metadata import PackageNotFoundError, version # pragma: no cover

try:
dist_name = "classifier-reborn"
__version__ = version(dist_name)
except PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
finally:
del version, PackageNotFoundError
50 changes: 29 additions & 21 deletions classifier/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

""" Classifier
----------------Contributors----------------
https://github.com/bhrigu123/classifier/graphs/contributors
https://github.com/iwishiwasaneagle/classifier/graphs/contributors
----------------Maintainer----------------
Bhrigu Srivastava <captain.bhrigu@gmail.com>
Jan-Hendrik Ewers <jh.ewers@gmail.com>
----------------License----------------
The MIT License [https://opensource.org/licenses/MIT]
Copyright (c) 2015 Bhrigu Srivastava http://bhrigu.me
Copyright (c) 2022 Jan-Hendrik Ewers https://janhendrikewers.uk

"""

Expand All @@ -16,9 +17,10 @@
import os
import subprocess
import sys
from loguru import logger

from classifier import __version__

VERSION = 'Classifier 2.0'
DIRCONFFILE = '.classifier.conf'
PLATFORM = sys.platform
OS = os.name
Expand Down Expand Up @@ -47,7 +49,11 @@ class Classifier:
Documents - https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions
"""

def __init__(self):
def __init__(self, test=False):
if not test:
self.setup_parser()

def setup_parser(self):
self.description = "Organize files in your directory instantly,by classifying them into different folders"
self.parser = argparse.ArgumentParser(description=self.description)

Expand Down Expand Up @@ -109,7 +115,7 @@ def create_default_config(self):
"DEBPackages: deb\n" +
"Programs: exe, msi\n" +
"RPMPackages: rpm")
print("CONFIG file created at: "+CONFIG)
logger.info("CONFIG file created at: "+CONFIG)

def checkconfig(self):
""" create a default config if not available """
Expand All @@ -131,7 +137,7 @@ def moveto(self, filename, from_folder, to_folder):
to_file = os.path.join(to_folder, filename)
# to move only files, not folders
if not to_file == from_file:
print('moved: ' + str(to_file))
logger.info('moved: ' + str(to_file))
if os.path.isfile(from_file):
if not os.path.exists(to_folder):
os.makedirs(to_folder)
Expand Down Expand Up @@ -162,19 +168,19 @@ def classify(self, formats, output, directory):
try:
self.moveto(file, directory, folder)
except Exception as e:
print('Cannot move file - {} - {}'.format(file, str(e)))
logger.info('Cannot move file - {} - {}'.format(file, str(e)))
"""
elif os.path.isdir(os.path.join(directory, file)) and self.args.recursive:
self.classify(self.formats, output, os.path.join(directory, file))
"""
return

def classify_by_date(self, date_format, output, directory):
print("Scanning Files")
logger.info("Scanning Files")

files = [x for x in os.listdir(directory) if not x.startswith('.')]
creation_dates = map(lambda x: (x, arrow.get(os.path.getctime(os.path.join(directory, x)))), files)
print(creation_dates)
logger.info(creation_dates)

for file, creation_date in creation_dates:
folder = creation_date.format(date_format)
Expand All @@ -197,13 +203,13 @@ def _format_arg(self, arg):
def run(self):
if self.args.version:
# Show version information and quit
print(VERSION)
logger.info(__version__)
return False

if self.args.types:
# Show file format information then quit
for key, value in self.formats.items():
print(key + ': '+ value)
logger.info(key + ': '+ value)
return False

if self.args.edittypes:
Expand All @@ -220,7 +226,7 @@ def run(self):
return

if bool(self.args.specific_folder) ^ bool(self.args.specific_types):
print(
logger.info(
'Specific Folder and Specific Types need to be specified together')
sys.exit()

Expand Down Expand Up @@ -251,7 +257,7 @@ def run(self):

if self.args.dateformat:
if not self.args.date:
print(
logger.info(
'Dateformat -df must be given alongwith date -dt option')
sys.exit()

Expand All @@ -261,30 +267,32 @@ def run(self):
else:
self.classify_by_date(self.dateformat, output, directory)
elif self.dirconf and os.path.isfile(self.dirconf):
print('Found config in current directory')
logger.info('Found config in current directory')
if self.args.output:
print('Your output directory is being ignored!!!')
logger.info('Your output directory is being ignored!!!')
for items in open(self.dirconf, "r"):
# reset formats for individual folders
self.formats = {}
try:
(key, dst, val) = items.split(':')
self.formats[key] = val.replace('\n', '').split(',')
print("\nScanning: " + directory +
logger.info("\nScanning: " + directory +
"\nFor: " + key +
'\nFormats: ' + val)
self.classify(self.formats, dst, directory)
except ValueError:
print("Your local config file is malformed. Please check and try again.")
logger.info("Your local config file is malformed. Please check and try again.")
return False
else:
print("\nScanning Folder: " + directory)
logger.info("\nScanning Folder: " + directory)
if self.args.specific_types:
print("For: " + str(self.formats.items()))
logger.info("For: " + str(self.formats.items()))
else:
print("Using the default CONFIG File\n")
logger.info("Using the default CONFIG File\n")
self.classify(self.formats, output, directory)

print("Done!\n")
logger.info("Done!\n")
return True

if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
# AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD!
requires = ["setuptools>=46.1.0", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
arrow==1.2.2
loguru==0.6.0
python-dateutil==2.8.2
six==1.16.0
73 changes: 73 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[metadata]
name = classifier-reborn
description = Classify the files in your Downloads folder into suitable destinations
author=Bhrigu Srivastava
[email protected]
maintainer=Jan-Hendrik Ewers
[email protected]
license = MIT
license_files = LICENSE.txt
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8; variant=GFM
url = https://github.com/iwishiwasaneagle/classifier/
project_urls =
Tracker = https://github.com/iwishiwasaneagle/classifier/issues


# Add here all kinds of additional classifiers as defined under
# https://pypi.org/classifiers/
classifiers =
Development Status :: 5 - Production/Stable
License :: OSI Approved :: MIT License
Operating System :: OS Independent


[options]
zip_safe = False
packages = find_namespace:
include_package_data = True

# Require a min/specific Python version (comma-separated conditions)
# python_requires = >=3.8

install_requires =
importlib-metadata; python_version<"3.8"
loguru==0.6.0
arrow==1.2.2


[options.packages.find]
where = ./
exclude =
tests

[options.extras_require]
test =
setuptools
pytest
pytest-cov
tox

[options.entry_points]
console_scripts =
classifier = classifier:main

[tool:pytest]
norecursedirs =
dist
build
.tox
testpaths = tests

[flake8]
max_line_length = 88
extend_ignore = E203, W503
# ^ Black-compatible
# E203 and W503 have edge cases handled by black
exclude =
.tox
build
dist
.eggs
docs/conf.py
per-file-ignores = "**/__init__.py:F401" # Unused import errors
33 changes: 15 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
"""
Setup file for classifier.
Use setup.cfg to configure your project.
"""
from setuptools import setup

setup(
name="classifier",
version="2.0",
description="Classify the files in your Downloads folder into suitable destinations.",
url="http://github.com/bhrigu123/classifier",
author="Bhrigu Srivastava",
author_email="[email protected]",
license='MIT',
packages=["classifier"],
entry_points="""
[console_scripts]
classifier = classifier.classifier:main
""",
install_requires=[
'arrow'
],
zip_safe=False
)
if __name__ == "__main__":
try:
setup()
except: # noqa
print(
"\n\nAn error occurred while building the project, "
"please ensure you have the most updated version of setuptools, "
"setuptools_scm and wheel with:\n"
" pip install -U setuptools setuptools_scm wheel\n\n"
)
raise
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
pytest-cov
Loading