diff --git a/.gitignore b/.gitignore index 42061c0..b9b1072 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -README.md \ No newline at end of file +README.md +env +Konsave.egg-info +build +dist \ No newline at end of file diff --git a/README.md b/README.md index 8434b41..f004bd1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/install.sh b/install.sh deleted file mode 100755 index 47013be..0000000 --- a/install.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# Print intro -echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~ - _ ___ __ -| | | \ \/ / Prayag Jain | Hax Guru -| |_| |\ / YouTube: https://youtube.com/c/haxguru -| _ |/ \ GitHub: https://github.com/Prayag2 -|_| |_/_/\_\ Email: prayagjain2@gmail.com - -~~~~~~~~~~~~~~~~~~~~~~~~~~~' -echo 'Installing konsave...' - -# Copy 'konsave' to ~/.local/bin/ -mkdir -p ~/.local/bin -cp ./konsave ~/.local/bin -chmod +x ~/.local/bin/konsave - -# Done -echo 'Installed successfully! You can now delete this folder.' -echo "Try 'konsave -h' for more info!" diff --git a/konsave/__init__.py b/konsave/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/konsave/__main__.py b/konsave/__main__.py new file mode 100755 index 0000000..2fb014b --- /dev/null +++ b/konsave/__main__.py @@ -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 = '') + parser.add_argument('-r', '--remove', required = False, type = int, help='Remove the specified profile', metavar = '') + parser.add_argument('-a', '--apply', required = False, type = int, help='Apply the specified profile', metavar = '') + parser.add_argument('-e', '--export-profile', required = False, type = int, help='Export a profile and share with your friends!', metavar = '') + parser.add_argument('-i', '--import-profile', required = False, type = str, help='Import a konsave file', metavar = '') + + ## 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() diff --git a/konsave/__pycache__/__init__.cpython-39.pyc b/konsave/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..590f937 Binary files /dev/null and b/konsave/__pycache__/__init__.cpython-39.pyc differ diff --git a/konsave/__pycache__/__main__.cpython-39.pyc b/konsave/__pycache__/__main__.cpython-39.pyc new file mode 100644 index 0000000..b02593d Binary files /dev/null and b/konsave/__pycache__/__main__.cpython-39.pyc differ diff --git a/konsave/__pycache__/funcs.cpython-39.pyc b/konsave/__pycache__/funcs.cpython-39.pyc new file mode 100644 index 0000000..3d13dbb Binary files /dev/null and b/konsave/__pycache__/funcs.cpython-39.pyc differ diff --git a/konsave/__pycache__/vars.cpython-39.pyc b/konsave/__pycache__/vars.cpython-39.pyc new file mode 100644 index 0000000..45b08ba Binary files /dev/null and b/konsave/__pycache__/vars.cpython-39.pyc differ diff --git a/konsave b/konsave/funcs.py old mode 100755 new mode 100644 similarity index 70% rename from konsave rename to konsave/funcs.py index 943648e..d09c9bc --- a/konsave +++ b/konsave/funcs.py @@ -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): @@ -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 @@ -41,6 +24,7 @@ def search_config(path, section, option): return config[section][option] +# RESTART KDE def restart_kde(): ''' Restarts @@ -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. @@ -62,6 +47,7 @@ def check_error(func, *args): return f +# PRINT/LOG def print_msg(msg): ''' Makes any text a little prettier @@ -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 @@ -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/ @@ -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 @@ -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 @@ -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 @@ -207,6 +198,7 @@ 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 @@ -214,9 +206,7 @@ def import_profile(path): # 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 @@ -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 = '') - parser.add_argument('-r', '--remove', required = False, type = int, help='Remove the specified profile', metavar = '') - parser.add_argument('-a', '--apply', required = False, type = int, help='Apply the specified profile', metavar = '') - parser.add_argument('-e', '--export-profile', required = False, type = int, help='Export a profile and share with your friends!', metavar = '') - parser.add_argument('-i', '--import-profile', required = False, type = str, help='Import a konsave file', metavar = '') - - ## 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!") \ No newline at end of file diff --git a/konsave/vars.py b/konsave/vars.py new file mode 100644 index 0000000..5ba8621 --- /dev/null +++ b/konsave/vars.py @@ -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) \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1fa68da --- /dev/null +++ b/setup.py @@ -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" + ] + } +) \ No newline at end of file