Skip to content

Commit

Permalink
Merge pull request #23 from Prayag2/python_early_support
Browse files Browse the repository at this point in the history
Python early version support
  • Loading branch information
Prayag2 authored Mar 7, 2021
2 parents 40cf633 + 4a95abf commit b47109e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- ``CHANGELOG.md`` file with [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.


## [1.1.4] - 2021-03-07
### Changes
- Created a function called `copy` to replace `shutil.copytree`. This would add support for python versions <= 3.7.
- Changed version in `vars.py` from 1.1.3 to 1.1.4

### Fixes
- Previously, running `konsave --export <id>` would cause it to export the CURRENT icon and cursor theme. Now, it will export the icon and cursor theme of the profile being exported.
- Some fixes in `copy()`

## [1.1.3] - 2021-03-06
### Changes
- Fixed something
Expand Down
Binary file modified konsave/__pycache__/__main__.cpython-39.pyc
Binary file not shown.
Binary file modified konsave/__pycache__/funcs.cpython-39.pyc
Binary file not shown.
Binary file modified konsave/__pycache__/vars.cpython-39.pyc
Binary file not shown.
55 changes: 43 additions & 12 deletions konsave/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,37 @@ def print_msg(msg):
print(f"Konsave: {msg}")


# COPY FILE/FOLDER
def copy(source, dest):
'''
This function was created because shutil.copytree gives error if the destination folder
exists and the argument "dirs_exist_ok" was introduced only after python 3.8.
This restricts people with python 3.7 or less from using Konsave.
This function will let people with python 3.7 or less use Konsave without any issues.
It uses recursion to copy files and folders from "source" to "dest"
'''
assert (type(source) == str and type(dest) == str), "Invalid path"
assert (source != dest), "Source and destination can't be same"
assert (os.path.exists(source)), "Source path doesn't exist"

if not os.path.exists(dest):
os.mkdir(dest)

if os.path.isdir(source):
for item in os.listdir(source):
source_path = os.path.join(source, item)
dest_path = os.path.join(dest, item)

if os.path.isdir(source_path):
copy(source_path, dest_path)
else:
if os.path.exists(dest_path):
os.remove(dest_path)
shutil.copy(source_path, dest)
else:
shutil.copy(source, dest)


# LIST PROFILES
def list_profiles(list_of_profiles, length_of_lop):
'''
Expand Down Expand Up @@ -126,7 +157,7 @@ def save_profile(name, list_of_profiles, force=False):
source = os.path.join(CONFIG_DIR, entry)
if os.path.exists(source):
if os.path.isdir(source):
shutil.copytree(source, f"{PROFILE_DIR}/{entry}", dirs_exist_ok=True)
check_error(copy, source, os.path.join(PROFILE_DIR, entry))
else:
shutil.copy(source, PROFILE_DIR)

Expand All @@ -149,7 +180,7 @@ def apply_profile(id, list_of_profiles, length_of_lop):
# run
name = list_of_profiles[id]
PROFILE_DIR = os.path.join(PROFILES_DIR, name)
shutil.copytree(PROFILE_DIR, CONFIG_DIR, dirs_exist_ok=True)
check_error(copy, PROFILE_DIR, CONFIG_DIR)
restart_kde()


Expand Down Expand Up @@ -202,10 +233,10 @@ def export(id, list_of_profiles, length_of_lop):
ICON_EXPORT_PATH = mkdir(os.path.join(EXPORT_PATH, "icons"))

# VARIABLES
KDE_GLOBALS = os.path.join(CONFIG_DIR, 'kdeglobals')
KDE_GLOBALS = os.path.join(PROFILE_DIR, 'kdeglobals')

icon = search_config(KDE_GLOBALS, 'Icons', 'Theme')
cursor = search_config(os.path.join(CONFIG_DIR, 'kcminputrc'), 'Mouse', 'cursorTheme')
cursor = search_config(os.path.join(PROFILE_DIR, 'kcminputrc'), 'Mouse', 'cursorTheme')

PLASMA_DIR = os.path.join(HOME, '.local/share/plasma')
LOCAL_ICON_DIR = os.path.join(HOME, '.local/share/icons', icon)
Expand All @@ -215,16 +246,16 @@ def export(id, list_of_profiles, length_of_lop):

def check_path_and_copy(path1, path2, export_location, name):
if os.path.exists(path1):
shutil.copytree(path1, os.path.join(export_location, name), dirs_exist_ok=True)
check_error(copy, path1, os.path.join(export_location, name))
elif os.path.exists(path2):
shutil.copytree(path2, os.path.join(export_location, name), dirs_exist_ok=True)
check_error(copy, path2, os.path.join(export_location, name))
else:
print_msg(f"Couldn't find {path1} or {path2}. Skipping...")

check_path_and_copy(LOCAL_ICON_DIR, USR_ICON_DIR, ICON_EXPORT_PATH, icon)
check_path_and_copy(LOCAL_CURSOR_DIR, USR_CURSOR_DIR, CURSOR_EXPORT_PATH, cursor)
shutil.copytree(PLASMA_DIR, PLASMA_EXPORT_PATH, dirs_exist_ok=True)
shutil.copytree(PROFILE_DIR, CONFIG_EXPORT_PATH, dirs_exist_ok=True)
check_error(copy, PLASMA_DIR, PLASMA_EXPORT_PATH)
check_error(copy, PROFILE_DIR, CONFIG_EXPORT_PATH)

shutil.make_archive(EXPORT_PATH, 'zip', EXPORT_PATH)
shutil.rmtree(EXPORT_PATH)
Expand Down Expand Up @@ -266,10 +297,10 @@ def import_profile(path):
PROFILE_DIR = os.path.join(PROFILES_DIR, item)

print()
shutil.copytree(CONFIG_IMPORT_PATH, PROFILE_DIR, dirs_exist_ok=True)
shutil.copytree(PLASMA_IMPORT_PATH, PLASMA_DIR, dirs_exist_ok=True)
shutil.copytree(ICON_IMPORT_PATH, LOCAL_ICON_DIR, dirs_exist_ok=True)
shutil.copytree(CURSOR_IMPORT_PATH, LOCAL_CURSOR_DIR, dirs_exist_ok=True)
check_error(copy, CONFIG_IMPORT_PATH, PROFILE_DIR)
check_error(copy, PLASMA_IMPORT_PATH, PLASMA_DIR)
check_error(copy, ICON_IMPORT_PATH, LOCAL_ICON_DIR)
check_error(copy, CURSOR_IMPORT_PATH, LOCAL_CURSOR_DIR)

shutil.rmtree(TEMP_PATH)

Expand Down
2 changes: 1 addition & 1 deletion konsave/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
list_of_profiles = os.listdir(PROFILES_DIR)
length_of_lop = len(list_of_profiles)

VERSION = "1.1.3"
VERSION = "1.1.4"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def read_desc():
packages=find_packages(),
package_data={'config': ['conf.yaml']},
include_package_data=True,
python_requires='>=3.7',
python_requires='>=3.6',
install_requires=['PyYaml'],
classifiers=[
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
Expand Down

0 comments on commit b47109e

Please sign in to comment.