Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Introduce a command-line interface #675

Merged
merged 31 commits into from
Dec 20, 2022
Merged

Introduce a command-line interface #675

merged 31 commits into from
Dec 20, 2022

Conversation

tfuxu
Copy link
Member

@tfuxu tfuxu commented Dec 10, 2022

Description

This PR introduces a CLI (command-line interface) for Gradience. It is currently highly work-in-progress, as I still need to write functions for the majority of commands, and some of the options doesn't yet have any help information. We are now at reviewing process, so in following days this PR should be merged into upstream.

CLI to-do list:

  • Add essential set of commands (presets, apply, new, download, monet),
  • Create logic code for commands:
    • presets
    • favorites
    • import
    • apply
    • new (will be worked on later)
    • download
    • monet
    • flatpak-overrides
    • help
  • Write help information for every option,
  • Support for local builds,
  • Flatpak support

Fixes #671

Type of change

  • Bugfix (Change which fixes a issue)
  • New feature (Change which adds new functionality)
  • Enhancement (Change which slightly improves existing code)
  • Breaking change (This change will introduce incompatibility with existing functionality)

Changelog

  • Added new command-line interface,
  • Moved many functions used for preset manipulation to backend/ modules,
  • Rewritten models/preset module to make it more readable,
  • Converted some backend modules to classes,
  • Made changes to log messages structure

Testing

  • I have tested my changes and verified that they work as expected

How to test the changes

Currently known working build types:

  • Local
  • Global
  • Flatpak
  • COPR
  • AUR

Notes:

To run CLI in Flatpak builds, use this command: flatpak run --command=gradience-cli com.github.GradienceTeam.Gradience.Devel

For local builds there is a small guide on how to get CLI working:

  1. Rebuild Gradience using either local.sh or Makefile,
  2. Run CLI with this command: ./local_cli.sh [command]

This commit is the first in a series of commits that will introduce new CLI interface for Gradience. Currently we need to move some parts of code that reside mostly in frontend modules to their new backend modules, and this commit is the beggining of this whole ordeal.

* Refactor Preset model object, in order to make it more readable and to allow `new` function that directly takes new values for properties
* Move presets_dir from models/preset to new backend/globals module
* Create new utils/colors module (will be used in later commits)
* Update all modules that are affected by above changes
* add more checks in new_preset_from_monet function
* return full Preset object instead of dict data
* remove some unused code
This commit adds a new CLI interface made using argparse library. Current status of CLI interface is very WIP, as it lacks logic for the majority of commands and doesn't work properly on Flatpak and local builds.
Currently working commands: monet, version
@0xMRTT
Copy link
Member

0xMRTT commented Dec 10, 2022

Thanks again @tfuxu for your contribution, if you need help for refactoring or things like that, i'll be glad to help.

Also, since that you refactored the repo structure, it'll be nice to be able to have multiple preset open at the same time or when a preset is opening by the user instead of erasing the current one, create a new window with the new preset. (@daudix-UFO will be happy 🚀 )

@daudix
Copy link
Member

daudix commented Dec 10, 2022

Yep, I would like to have an option to open new gradience window, this would be really helpful when creating themes with multiple variants

@tfuxu
Copy link
Member Author

tfuxu commented Dec 10, 2022

Thanks again @tfuxu for your contribution, if you need help for refactoring or things like that, i'll be glad to help.

I currently need to move functions for accessing a list of installed and favorited presets from frontend to backend, so if you want, you can try to move them (put them in theming/preset_utils module) while I'm adding logic to other commands.

Also, since that you refactored the repo structure, it'll be nice to be able to have multiple preset open at the same time or when a preset is opening by the user instead of erasing the current one, create a new window with the new preset. (daudix-UFO will be 🚀 )

Sure, should be relatively easy to add, but I think that this exceeds the point of this PR, so maybe in a later date I could look into that.

@0xMRTT
Copy link
Member

0xMRTT commented Dec 10, 2022

Thanks again @tfuxu for your contribution, if you need help for refactoring or things like that, i'll be glad to help.

I currently need to move functions for accessing a list of installed and favorited presets from frontend to backend, so if you want, you can try to move them (put them in theming/preset_utils module) while I'm adding logic to other commands.

Also, since that you refactored the repo structure, it'll be nice to be able to have multiple preset open at the same time or when a preset is opening by the user instead of erasing the current one, create a new window with the new preset. (daudix-UFO will be 🚀 )

Sure, should be relatively easy to add, but I think that this exceeds the point of this PR, so maybe in a later date I could look into that.

Ofc

@tfuxu tfuxu changed the title Introduce new CLI Introduce a command-line interface Dec 10, 2022
@tfuxu
Copy link
Member Author

tfuxu commented Dec 12, 2022

@0xMRTT
Are you going to port these functions? Just asking, because I did most of the logic already and wanted to finish doing it for list commands too.

@niksingh710
Copy link

Will the be added in aur as gradience-cli ? for testing??

@tfuxu
Copy link
Member Author

tfuxu commented Dec 17, 2022

Will the be added in aur as gradience-cli ? for testing??

No, you won't be able to install CLI as a standalone package, because it is tied directly to Gradience code. The only way to get CLI will be to download a full Gradience package.

@daudix
Copy link
Member

daudix commented Dec 18, 2022

how I can download a preset? for some reason it does not work for me

❯ flatpak run --command=gradience-cli com.github.GradienceTeam.Gradience.Devel download -n tokyonight-dark
[Gradience] ERROR: No presets found with text: tokyonight-dark

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

You need to type display name (don't forget to put it in quotes if it has spaces in name)

@daudix
Copy link
Member

daudix commented Dec 18, 2022

❯ flatpak run --command=gradience-cli com.github.GradienceTeam.Gradience.Devel download --preset-name "Tokyo Night Dark"
[Gradience] ERROR: No presets found with text: Tokyo Night Dark                                                         

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

❯ flatpak run --command=gradience-cli com.github.GradienceTeam.Gradience.Devel download --preset-name "Tokyo Night Dark"
[Gradience] ERROR: No presets found with text: Tokyo Night Dark                                                         

Looks like a bug. Well, I'll check what's wrong here, and try to fix that.

@daudix
Copy link
Member

daudix commented Dec 18, 2022

apply command acts oddly too, looks like flatpak does not have access to home folder

flatpak run --env=LANG=en --command=gradience-cli com.github.GradienceTeam.Gradience.Devel import -p ~/cobalt-dark.json

(process:2): Gtk-WARNING **: 20:02:45.321: Locale not supported by C library.
	Using the fallback 'C' locale.
[Gradience] �[1;36mINFO:�[0m Importing preset: cobalt-dark.json
Traceback (most recent call last):
  File "/app/bin/gradience-cli", line 361, in <module>
    cli = CLI()
  File "/app/bin/gradience-cli", line 117, in __init__
    self.__parse_args()
  File "/app/bin/gradience-cli", line 138, in __parse_args
    self.import_preset(args)
  File "/app/bin/gradience-cli", line 226, in import_preset
    shutil.copy(
  File "/usr/lib/python3.10/shutil.py", line 417, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.10/shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/var/home/daudix/cobalt-dark.json'

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

That's because you try to import preset from /var/home/daudix location where it doesn't exist. You need to put absolute path. Nevermind, it actually works with ~ symbol.

@daudix
Copy link
Member

daudix commented Dec 18, 2022

hmm, strange

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

Well, that's a bummer. I've checked import command now on Flatpak, and you actually need to give permissions to get it to work.

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

I think I have an idea how to fix this.
Maybe I've could create a function which would execute if it was detected that CLI is running in sandbox, that would ask user from what directory he wants to import a preset. It will then temporary add a permission in flatpak overrides which will give Gradience an access to that directory, and after importing is done, it will remove this permission. If it will work, I'll could implement this also in monet command to get it working as well.

@daudix
Copy link
Member

daudix commented Dec 18, 2022

If only libportal were working from cli

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

Fixed bug from #675 (comment)

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

Okay, I was able to create a function from functions in backend/flatpak_overrides that gives read/write access to a directory specified by a user. The only problem is that Flatpak (of course) doesn't dynamically load permission changes into running sandboxed application, so user will have to type two different commands to get it working 😒️

@daudix
Copy link
Member

daudix commented Dec 18, 2022

OK, it's not a big deal to enable one checkbox in Flatseal, or we can add access to downloads folder and say user that you need to put preset there?

@tfuxu
Copy link
Member Author

tfuxu commented Dec 18, 2022

we can add access to downloads folder and say user that you need to put preset there?

That might be an idea to consider

@tfuxu
Copy link
Member Author

tfuxu commented Dec 19, 2022

Okay, another idea.
I'll do a mishmash of both mine and yours idea, so we will allow Gradience to access Downloads folder by default, but I'll use my function to create a command in CLI that will allow users to choose which additional directories they want to allow Gradience to read.

@tfuxu
Copy link
Member Author

tfuxu commented Dec 19, 2022

This is how it will look as a command:

usage: gradience-cli access-file [-h] [-l] [-a PATH] [-d PATH]

options:
  -h, --help            show this help message and exit
  -l, --list            list allowed directories and files
  -a PATH, --allow PATH
                        allow Gradience to access this file or directory
  -d PATH, --disallow PATH
                        disallow Gradience access to this file or directory

@tfuxu
Copy link
Member Author

tfuxu commented Dec 19, 2022

Okay, I've tested new commits on Flatpak and now everything works as expected.

@tfuxu
Copy link
Member Author

tfuxu commented Dec 20, 2022

Alright, @daudix-UFO everything tested? Can we merge?

@daudix
Copy link
Member

daudix commented Dec 20, 2022

@tfuxu I think we can! 🚀

@tfuxu tfuxu merged commit b5a4dc0 into main Dec 20, 2022
@tfuxu tfuxu deleted the cli-support branch December 20, 2022 23:15
@niksingh710
Copy link

As it is merged now.
Is it accessible in flatpak build or have to wait for the release?
and will it be available in Aur?

@daudix
Copy link
Member

daudix commented Dec 21, 2022

As it is merged now. Is it accessible in flatpak build or have to wait for the release? and will it be available in Aur?

You have to wait for the release, yes it will be available in aur

@daudix daudix mentioned this pull request Jan 9, 2023
1 task
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: be able to apply gradience themes from console
4 participants