Skip to content

Commit

Permalink
ADDED TO PYPI! FINALLY!
Browse files Browse the repository at this point in the history
  • Loading branch information
Prayag2 committed Mar 5, 2021
1 parent fc290c5 commit 57e3971
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 102 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
README.md
README.md
env
Konsave.egg-info
build
dist
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ A CLI program that will let you save and apply your KDE Plasma customizations wi

---
## Dependencies
There are no dependencies! Just make sure your python version is above `3.8`.
There are no dependencies! Just make sure your python version is above `3.9`.

## Installation
- Clone This repo
`git clone https://github.com/Prayag2/konsave ~/Downloads/konsave`
- Make it executable
`cd ~/Downloads/konsave`
`chmod +x ./install.sh`
- Install
`./install.sh`
Install from PyPI
`python -m pip install konsave`

## Usage
### Get Help
Expand Down
20 changes: 0 additions & 20 deletions install.sh

This file was deleted.

Empty file added konsave/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions konsave/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## IMPORT ##
import os, argparse
from konsave.funcs import *


## MAIN ##
def main():

## 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', required = False, action = 'store_true', help='Lists created profiles')
parser.add_argument('-s', '--save', required = False, type = str, help='Save current config as a profile', metavar = '<name>')
parser.add_argument('-r', '--remove', required = False, type = int, help='Remove the specified profile', metavar = '<id>')
parser.add_argument('-a', '--apply', required = False, type = int, help='Apply the specified profile', metavar = '<id>')
parser.add_argument('-e', '--export-profile', required = False, type = int, help='Export a profile and share with your friends!', metavar = '<id>')
parser.add_argument('-i', '--import-profile', required = False, type = str, help='Import a konsave file', metavar = '<path>')

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

## CHECKING FOR ARGUMENTS ##
if args.list:
check_error(list_profiles, list_of_profiles, length_of_lop)
elif args.save != None:
check_error(save_profile, args.save, list_of_profiles)
elif args.remove != None:
check_error(remove_profile, args.remove, list_of_profiles, length_of_lop)
elif args.apply != None:
check_error(apply_profile, args.apply, list_of_profiles, length_of_lop)
elif args.export_profile != None:
check_error(export, args.export_profile, list_of_profiles, length_of_lop)
elif args.import_profile != None:
check_error(import_profile, args.import_profile)
else:
parser.print_help()



## CALLING MAIN ##
if __name__ == '__main__':
main()
Binary file added konsave/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added konsave/__pycache__/__main__.cpython-39.pyc
Binary file not shown.
Binary file added konsave/__pycache__/funcs.cpython-39.pyc
Binary file not shown.
Binary file added konsave/__pycache__/vars.cpython-39.pyc
Binary file not shown.
87 changes: 14 additions & 73 deletions konsave → konsave/funcs.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
#!/usr/bin/python3
# _ ___ __
# | | | \ \/ / Prayag Jain | Hax Guru
# | |_| |\ / YouTube: https://youtube.com/c/haxguru
# | _ |/ \ GitHub: https://github.com/Prayag2
# |_| |_/_/\_\ Email: prayagjain2@gmail.com
#

## IMPORT ##
import os, shutil, argparse, configparser
from random import shuffle
from zipfile import is_zipfile, ZipFile


## GLOBAL VARIABLES ##
HOME = os.path.expandvars('$HOME')
CONFIG_DIR = os.path.join(HOME, '.config')
KONSAVE_DIR = os.path.join(CONFIG_DIR, 'konsave')
PROFILES_DIR = os.path.join(KONSAVE_DIR, 'profiles')

folder_names = ['gtk-2.0', 'gtk-3.0', 'gtk-4.0', 'Kvantum', 'latte']
file_names = ['dolphinrc', 'konsolerc', 'kcminputrc', 'kdeglobals', 'kglobalshortcutsrc', 'klipperrc', 'krunnerrc', 'kscreenlockerrc', 'ksmserverrc', 'kwinrc', 'kwinrulesrc', 'plasma-org.kde.plasma.desktop-appletsrc', 'plasmarc', 'plasmashellrc', 'gtkrc', 'gtkrc-2.0', 'lattedockrc', 'breezerc', 'oxygenrc', 'lightlyrc', 'ksplashrc']
export_extension = '.knsv'

from konsave.vars import *

## FUNCTIONS ##
def mkdir(path):
Expand All @@ -32,6 +13,8 @@ def mkdir(path):
os.makedirs(path)
return path


# PARSE AND SEARCH IN A CONFIG FILE
def search_config(path, section, option):
'''
This function will parse config files and search for specific values
Expand All @@ -41,6 +24,7 @@ def search_config(path, section, option):
return config[section][option]


# RESTART KDE
def restart_kde():
'''
Restarts
Expand All @@ -50,6 +34,7 @@ def restart_kde():
print("Konsave: Profile applied successfully! Please log-out and log-in to see the changes completely!")


# CHECK FOR ERRORS
def check_error(func, *args):
'''
This function runs a function and checks if there are any errors.
Expand All @@ -62,6 +47,7 @@ def check_error(func, *args):
return f


# PRINT/LOG
def print_msg(msg):
'''
Makes any text a little prettier
Expand All @@ -70,6 +56,7 @@ def print_msg(msg):
print(f"Konsave: {msg}")


# LIST PROFILES
def list_profiles(list_of_profiles, length_of_lop):
'''
Lists all the created profiles
Expand All @@ -85,6 +72,7 @@ def list_profiles(list_of_profiles, length_of_lop):
print(f"{i+1}\t{item}")


# SAVE PROFILE
def save_profile(name, list_of_profiles):
'''
Saves necessary config files in ~/.config/konsave/profiles/<name>
Expand All @@ -110,6 +98,7 @@ def save_profile(name, list_of_profiles):
print_msg('Profile saved successfully!')


# APPLY PROFILE
def apply_profile(id, list_of_profiles, length_of_lop):
'''
Applies profile of the given id
Expand All @@ -129,6 +118,7 @@ def apply_profile(id, list_of_profiles, length_of_lop):
restart_kde()


# REMOVE PROFILE
def remove_profile(id, list_of_profiles, length_of_lop):
'''
Removes the specified profile
Expand All @@ -146,6 +136,7 @@ def remove_profile(id, list_of_profiles, length_of_lop):
print_msg('removed profile successfully')


# EXPORT PROFILE
def export(id, list_of_profiles, length_of_lop):
'''
It will export the specified profile as a ".knsv" file in the home directory
Expand Down Expand Up @@ -207,16 +198,15 @@ def check_path_and_copy(path1, path2, export_location, name):
print_msg(f"Successfully exported to {EXPORT_PATH}{export_extension}")


# IMPORT PROFILE
def import_profile(path):
'''
This will import an exported profile
'''

# assert
assert (is_zipfile(path) and path[-5:] == export_extension), "Not a valid konsave file"

item = os.path.basename(path)[:-5]

item = os.path.basename(path)[:-5]
assert (not os.path.exists(os.path.join(PROFILES_DIR, item))), "A profile with this name already exists"

# run
Expand Down Expand Up @@ -248,53 +238,4 @@ def import_profile(path):

shutil.rmtree(TEMP_PATH)

print_msg("Profile successfully imported!")


## MAIN ##
def main():

## VARIABLES ##
mkdir(PROFILES_DIR)
list_of_profiles = os.listdir(PROFILES_DIR)
length_of_lop = len(list_of_profiles)


## 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', required = False, action = 'store_true', help='Lists created profiles')
parser.add_argument('-s', '--save', required = False, type = str, help='Save current config as a profile', metavar = '<name>')
parser.add_argument('-r', '--remove', required = False, type = int, help='Remove the specified profile', metavar = '<id>')
parser.add_argument('-a', '--apply', required = False, type = int, help='Apply the specified profile', metavar = '<id>')
parser.add_argument('-e', '--export-profile', required = False, type = int, help='Export a profile and share with your friends!', metavar = '<id>')
parser.add_argument('-i', '--import-profile', required = False, type = str, help='Import a konsave file', metavar = '<path>')

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

## CHECKING FOR ARGUMENTS ##
if args.list:
check_error(list_profiles, list_of_profiles, length_of_lop)
elif args.save != None:
check_error(save_profile, args.save, list_of_profiles)
elif args.remove != None:
check_error(remove_profile, args.remove, list_of_profiles, length_of_lop)
elif args.apply != None:
check_error(apply_profile, args.apply, list_of_profiles, length_of_lop)
elif args.export_profile != None:
check_error(export, args.export_profile, list_of_profiles, length_of_lop)
elif args.import_profile != None:
check_error(import_profile, args.import_profile)
else:
parser.print_help()



## CALLING MAIN ##
if __name__ == '__main__':
main()
print_msg("Profile successfully imported!")
19 changes: 19 additions & 0 deletions konsave/vars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## 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')
PROFILES_DIR = os.path.join(KONSAVE_DIR, 'profiles')

folder_names = ['gtk-2.0', 'gtk-3.0', 'gtk-4.0', 'Kvantum', 'latte']
file_names = ['dolphinrc', 'konsolerc', 'kcminputrc', 'kdeglobals', 'kglobalshortcutsrc', 'klipperrc', 'krunnerrc', 'kscreenlockerrc', 'ksmserverrc', 'kwinrc', 'kwinrulesrc', 'plasma-org.kde.plasma.desktop-appletsrc', 'plasmarc', 'plasmashellrc', 'gtkrc', 'gtkrc-2.0', 'lattedockrc', 'breezerc', 'oxygenrc', 'lightlyrc', 'ksplashrc']
export_extension = '.knsv'

if not os.path.exists(PROFILES_DIR):
os.mkdirs(PROFILES_DIR)

list_of_profiles = os.listdir(PROFILES_DIR)
length_of_lop = len(list_of_profiles)
29 changes: 29 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from setuptools import setup, find_packages

def read_desc():
with open('README.md', 'r') as desc:
return desc.read()

setup (
name="Konsave",
version="1.0.3",
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_content_type="text/markdown",
url="https://www.github.com/prayag2/konsave/",
packages=find_packages(),
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'
],
entry_points={
'console_scripts': [
"konsave = konsave.__main__:main"
]
}
)

0 comments on commit 57e3971

Please sign in to comment.