Skip to content

Commit

Permalink
Merge pull request #30 from Prayag2/pkg_maintenance
Browse files Browse the repository at this point in the history
Package maintenance
  • Loading branch information
Prayag2 authored Mar 16, 2021
2 parents 51fbb82 + 3f237b7 commit 062ce23
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 76 deletions.
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Byte-compiled / optimized / DLL files
__pycache__
**/__pycache__
*.py[cod]
*$py.class

Expand Down Expand Up @@ -137,3 +137,17 @@ dmypy.json

# Cython debug symbols
cython_debug/

# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# JetBrains User-specific stuff
.idea/**
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[MASTER]
disable=broad-except, too-many-locals
disable=broad-except, too-many-locals
2 changes: 1 addition & 1 deletion CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage], versi
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
[version]: http://contributor-covenant.org/version/1/4/
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
</p>

---
## Dependencies
### PyYaml
`pip install pyyaml`

## Installation
Install from PyPI
Expand Down
36 changes: 17 additions & 19 deletions konsave/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""
This is the main module
"""
"""Konsave entry point."""

## IMPORT ##
import argparse
from konsave.funcs import (
list_profiles,
Expand All @@ -16,18 +13,17 @@
from konsave.vars import VERSION, list_of_profiles, length_of_lop


## MAIN ##
def main():
"""
The main function that handles all the arguments and options
def _get_parser() -> argparse.ArgumentParser:
"""Returns CLI parser.
Returns:
argparse.ArgumentParser: Created parser.
"""
## PARSER SETTINGS ##
parser = argparse.ArgumentParser(
prog="Konsave",
epilog="Please report bugs at https://www.github.com/prayag2/konsave",
)

## ADDING ARGS ##
parser.add_argument(
"-l",
"--list",
Expand Down Expand Up @@ -89,21 +85,24 @@ def main():
"-w", "--wipe", required=False, action="store_true", help="Wipes all profiles."
)

## PARSING ARGS ##
args = parser.parse_args()
return parser


def main():
"""The main function that handles all the arguments and options."""
args = _get_parser().parse_args()

## CHECKING FOR ARGUMENTS ##
if args.list:
list_profiles(list_of_profiles, length_of_lop)
elif args.save is not None:
elif args.save:
save_profile(args.save, list_of_profiles, args.force)
elif args.remove is not None:
elif args.remove:
remove_profile(args.remove, list_of_profiles, length_of_lop)
elif args.apply is not None:
elif args.apply:
apply_profile(args.apply, list_of_profiles, length_of_lop)
elif args.export_profile is not None:
elif args.export_profile:
export(args.export_profile, list_of_profiles, length_of_lop)
elif args.import_profile is not None:
elif args.import_profile:
import_profile(args.import_profile)
elif args.version:
print(f"Konsave: {VERSION}")
Expand All @@ -113,6 +112,5 @@ def main():
parser.print_help()


## CALLING MAIN ##
if __name__ == "__main__":
main()
Binary file removed konsave/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file removed konsave/__pycache__/__main__.cpython-39.pyc
Binary file not shown.
Binary file removed konsave/__pycache__/funcs.cpython-39.pyc
Binary file not shown.
Binary file removed konsave/__pycache__/vars.cpython-39.pyc
Binary file not shown.
45 changes: 13 additions & 32 deletions konsave/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This module contains all the functions for konsave.
"""

## IMPORT ##
import os
import shutil
import sys
Expand All @@ -27,10 +26,8 @@
) from error


## FUNCTIONS ##
# ERROR HANDLING DECORATOR
def exception_handler(func):
"""Handles errors and prints nicely
"""Handles errors and prints nicely.
Args:
func: any function
Expand All @@ -52,7 +49,7 @@ def inner_func(*args, **kwargs):


def mkdir(path):
"""Creates directory if it doesn't exist
"""Creates directory if it doesn't exist.
Args:
path: path to the new directory
Expand All @@ -65,9 +62,8 @@ def mkdir(path):
return path


# PRINT/LOG
def log(msg, *args, **kwargs):
"""Logs text
"""Logs text.
Args:
msg: the text to be printed
Expand All @@ -77,19 +73,15 @@ def log(msg, *args, **kwargs):
print(f"Konsave: {msg.capitalize()}", *args, **kwargs)


# RESTART KDE
def restart_kde():
"""
Replaces plasmashell
"""
"""Replaces plasmashell."""
log("restarting kde...")
os.system("plasmashell --replace > /dev/null 2>&1 & disown")


# PARSE AND SEARCH IN A CONFIG FILE
@exception_handler
def search_config(path, section, option):
"""This function will parse config files and search for specific values
"""This function will parse config files and search for specific values.
Args:
path: path to a config file
Expand All @@ -104,10 +96,9 @@ def search_config(path, section, option):
return config[section][option]


# LOAD CONFIG FILE
@exception_handler
def load_config():
"""Loads config file
"""Loads config file.
Returns:
list: the names of files and folders in conf.yaml
Expand All @@ -124,7 +115,6 @@ def load_config():
return config["entries"]


# COPY FILE/FOLDER
@exception_handler
def copy(source, dest):
"""
Expand Down Expand Up @@ -158,10 +148,9 @@ def copy(source, dest):
shutil.copy(source_path, dest)


# LIST PROFILES
@exception_handler
def list_profiles(profile_list, profile_count):
"""Lists all the created profiles
"""Lists all the created profiles.
Args:
profile_list: the list of all created profiles
Expand All @@ -178,10 +167,9 @@ def list_profiles(profile_list, profile_count):
print(f"{i + 1}\t{item}")


# SAVE PROFILE
@exception_handler
def save_profile(name, profile_list, force=False):
"""Saves necessary config files in ~/.config/konsave/profiles/<name>
"""Saves necessary config files in ~/.config/konsave/profiles/<name>.
Args:
name: name of the profile
Expand Down Expand Up @@ -209,10 +197,9 @@ def save_profile(name, profile_list, force=False):
log("Profile saved successfully!")


# APPLY PROFILE
@exception_handler
def apply_profile(profile_id, profile_list, profile_count):
"""Applies profile of the given id
"""Applies profile of the given id.
Args:
profile_id: id of the profile to be applied
Expand Down Expand Up @@ -241,10 +228,9 @@ def apply_profile(profile_id, profile_list, profile_count):
)


# REMOVE PROFILE
@exception_handler
def remove_profile(profile_id, profile_list, profile_count):
"""Removes the specified profile
"""Removes the specified profile.
Args:
profile_id: id of the profile to be removed
Expand All @@ -265,10 +251,9 @@ def remove_profile(profile_id, profile_list, profile_count):
log("removed profile successfully")


# EXPORT PROFILE
@exception_handler
def export(profile_id, profile_list, profile_count):
"""It will export the specified profile as a ".knsv" file in the home directory
"""It will export the specified profile as a ".knsv" file in the home directory.
Args:
profile_id: id of the profile to be exported
Expand Down Expand Up @@ -347,10 +332,9 @@ def check_path_and_copy(path1, path2, export_location, name):
log(f"Successfully exported to {export_path}{EXPORT_EXTENSION}")


# IMPORT PROFILE
@exception_handler
def import_profile(path):
"""This will import an exported profile
"""This will import an exported profile.
Args:
path: path of the `.knsv` file
Expand Down Expand Up @@ -402,12 +386,9 @@ def import_profile(path):
log("Profile successfully imported!")


# WIPE
@exception_handler
def wipe():
"""
This function will wipe all profiles
"""
"""Wipes all profiles."""
confirm = input('This will wipe all your profiles. Enter "WIPE" Tto continue: ')
if confirm == "WIPE":
shutil.rmtree(PROFILES_DIR)
Expand Down
2 changes: 0 additions & 2 deletions konsave/vars.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""
This module contains all the variables for konsave
"""
## IMPORT ##
import os


## GLOBAL VARS ##
HOME = os.path.expandvars("$HOME")
CONFIG_DIR = os.path.join(HOME, ".config")
KONSAVE_DIR = os.path.join(CONFIG_DIR, "konsave")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYaml==5.4.1
4 changes: 4 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aiohttp>=3.7.4
aiohttp_cors>=0.7.0
black>=20.8b1
pylint>=2.7.2
53 changes: 36 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
"""
Setup module
"""
"""Setup module"""

from pathlib import Path
from typing import List

from setuptools import setup, find_packages


def read_desc():
"""Reads the README
def _read_desc() -> str:
"""Reads the README.md.
Returns:
str: Contents of README.md file.
"""
with open('README.md', 'r') as desc:
with open("README.md", "r") as desc:
return desc.read()


def _read_reqs(path: Path) -> List[str]:
"""Reads a pip requirement file.
Args:
path (Path): Path to pip requirements file.
Returns:
:type: list of str: List of dependency identifiers.
"""
with open(path, "r") as file:
return file.readlines()


# Package requirements
_REQUIREMENTS: List[str] = _read_reqs(Path("requirements.txt"))
_REQUIREMENTS_DEV: List[str] = _read_reqs(Path("requirements_dev.txt"))

setup(
name="Konsave",
use_scm_version=True,
setup_requires=['setuptools_scm'],
setup_requires=["setuptools_scm"],
author="Prayag Jain",
author_email="prayagjain2@gmail.com",
description="A program that lets you save your Plasma configuration in an instant!",
long_description=read_desc(),
long_description=_read_desc(),
long_description_content_type="text/markdown",
url="https://www.github.com/prayag2/konsave/",
packages=find_packages(),
package_data={'config': ['conf.yaml']},
package_data={"config": ["conf.yaml"]},
include_package_data=True,
python_requires='>=3.6',
install_requires=['PyYaml'],
python_requires=">=3.6",
install_requires=_REQUIREMENTS,
extras_require={"dev": _REQUIREMENTS_DEV},
classifiers=[
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: POSIX",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
'Programming Language :: Python'
"Programming Language :: Python",
],
entry_points={
'console_scripts': [
"konsave = konsave.__main__:main"
]
}
entry_points={"console_scripts": ["konsave = konsave.__main__:main"]},
)

0 comments on commit 062ce23

Please sign in to comment.