Skip to content

Commit

Permalink
Updates based on NFC43-dev repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Lich-Corals committed Feb 19, 2024
1 parent 2c7dee0 commit 19b080a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 41 deletions.
83 changes: 68 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ A python script to extend Nautilus using nautilus-python.
3. [Install the extension](#23-install-the-extension)
3. [Configuration](#3-configuration)
1. [Automatic updates](#31-automatic-updates)
2. [Manual update trigger](#32-manual-update-trigger)
3. [Shown menu items](#33-shown-menu-items)
4. [Patch note popup](#34-patch-note-popup)
2. [Shown menu items](#32-shown-menu-items)
3. [Other options](#33-other-options)
4. [Updating](#4-updating)
5. [Usage](#5-usage)
6. [Any questions?](#6-any-questions)
7. [Credits](#7-credits)
6. [Warnings and errors](#6-warnings-and-errors)
7. [Any questions?](#7-any-questions)
8. [Credits](#8-credits)

# 1. Features
This programm can convert images, audio files and videos with the help of the default context menu in Nautilus. It works with a single Python script and has few depnendncy programms. It should work with every version of nautilus.
This program can convert images, audio files and videos with the help of the default context menu in Nautilus. It works with a single Python script and has few depnendncy programs. It should work with every version of nautilus.
```mermaid
flowchart TD
A[Supported Image Files]
Expand Down Expand Up @@ -145,7 +145,7 @@ You may need to [install it manually](https://github.com/olokelo/jxlpy#build-it-
# 3. Configuration
The program can be configured using the NFC43-Config.json file, which will be created in the installation dictionary when the script is executed for the first time.
Just modify the file, by changing the 'true' and 'false' values.
If the program is installed in a root location, then you need to change the configuration inside the script.
If the program is installed in a root location, you need to change the configuration inside the script.
<b>Don't forget to save your changes, and restart nautilus after modifying the configuration!</b>
```bash
#Quit nautilus
Expand All @@ -157,23 +157,22 @@ If the program is installed in a root location, then you need to change the conf
## 3.1 Automatic updates
Automatic updates are only working in the home dictionary. If you've installed the script at the system-wide location, you may turn off automatic updates.
<br/><br/>To <b>turn off automatic updates</b>, open the config file with a text editor and set the `automaticUpdates` variable to 'false'.

## 3.2 Manual update trigger
To <b>manually trigger a self-update</b>, just open the .py file with a text editor and change the value of the `converterVersion` variable.

## 3.3 Shown menu items
## 3.2 Shown menu items
To turn off the <b>patch note button</b> in the context menu, open the config file with a text editor and set the `showPatchNoteButton` variable to 'false'.
<br/><br/>To turn off the <b>Configure NFC43 button</b> in the context menu, open the config file with a text editor and set the `showConfigHint` variable to 'false'.
<br/><br/>To turn off the '<b>convert to square</b>' option, open the config file with a text editor and set the `convertToSquares` variable to 'false'.
<br/><br/>To turn off the '<b>convert to wallpaper</b>' function, open the config file with a text editor and set the `convertToWallpapers` variable to 'false'.

## 3.4 Patch note pop-up
## 3.3 Other options
To turn off the <b>patch note pop-up</b>, open the config file with a text editor and set the `showPatchNotes` variable to 'false'.
To turn off the <b>Double script installation Warning</b>, open the config file with a text editor and set the `checkForDoubleInstallation` variable to 'false'.

# 4. Updating
If the script is installed in the home folder (~/.local/share/nautilus-python/extensions/), it will update automatically as long as the automatic updates aren't disabled.
If the script is installed in the home folder (~/.local/share/nautilus-python/extensions/) or has permissions to write in it's dictionary, it will update automatically as long as the automatic updates aren't disabled.

If automatic updates are disabled or the script is installed in the root folder, you can run the installation commands again.
If automatic updates are disabled, you can run the installation commands again to update the program.
# 5. Usage

Just right click on an supported file and choose the "Convert to..." option. In this sub menu you can select any file type you want to convert to.
Expand All @@ -182,14 +181,68 @@ Converting a file can take some time. There is no indicator when the process is

If you experience any issues with the extension, please report it on the [issues](https://github.com/Lich-Corals/nautilus-fileconverter/issues) page.

# 6. Any questions?
# 6. Warnings and errors
## WARNING(Nautilus-file-converter)(XXX):

### (000): "pyheif" not found
<b>Causes:</b><br/>
This warning is caused, because the script is not able to find your pyheif installation.
<br/><br/><b>Possible Effects:</b><br/>
Without pyheif, the converter won't be able to convert from heif file format.
<br/><br/><b>How to solve?</b><br/>
To solve this warning, you need to install pyheif using pip.
View the [Optional dependencies](#22-optional-dependencies) section to get installation instructions.
### (001): "jxlpy" not found
<b>Causes:</b><br/>
This warning is caused, because the script is not able to find your jxlpy installation.
<br/><br/><b>Possible Effects:</b><br/>
Without jxlpy, the converter won't be able to convert from- or to jxl file format.
<br/><br/><b>How to solve?</b><br/>
To solve this warning, you need to install jxlpy using pip.
<br/>View the [Optional dependencies](#22-optional-dependencies) section to get installation instructions.

### (002): No permission to self-update
<b>Causes:</b><br/>
The program has no permission to write it's own file.
<br/>This warning usually occurs when the script is located at "/usr/share/nautilus-python/extensions/".
<br/><br/><b>Possible Effects:</b><br/>
The self-update function will not be available.
<br/>The script may show the releases page on multiple startups if self-update isn't disabled.
<br/><br/><b>How to solve?</b><br/>
To remove the release popup, you may disable the corresponding setting. To do this, please follow the instructions on the [configuration page](#3-configuration).
<br/>To get self updates, the script needs the permissions to write to itself. This can be done by changing the file permissions using [chmod](https://www.man7.org/linux/man-pages/man1/chmod.1.html) or by running the script as a privileged user.
<br/>To be able to self-update, the user, who is executing the script (by starting nautilus) needs permissions to edit the script itself.

### (003): No permission to write configuration file
<b>Causes:</b><br/>
The program has no permission to write in the dictionary where it is installed.
<br/>This warning usually occurs when the script is located at "/usr/share/nautilus-python/extensions/".
<br/><br/><b>Possible Effects:</b><br/>
The self-update function may not be available.
<br/>The script needs to be configured by editing the script itself.
<br/>If self-updating is enabled, the script's configuration will reset when a update is performed.
<br/><br/><b>How to solve?</b><br/>
To fix this, the script needs the permissions to write inside the folder, where it is located. This can be done by changing the folder permissions using [chmod](https://www.man7.org/linux/man-pages/man1/chmod.1.html) or by running the script as a privileged user.
<br/>To use the configuration file, the user, who is executing the script (by starting nautilus) needs permissions create and edit files inside the installation dictionary.
<br/><br/>To prevent the settings from being reset, you can add a config file to the dictionary. Note that the file will not be update if new configurations are added.
### (004): Double script installation detected
<b>Causes:</b><br/>
The script is installed in a home location and finds another script with the same name in the root installation folder ("/usr/share/nautilus-python/extensions/").
<br/><br/><b>Possible Effects:</b><br/>
The context menu may appear two times.
<br/><br/><b>How to solve?</b><br/>
To solve this issue, you have to remove one of the files (in "/usr/share/nautilus-python/extensions/" or in "~/.local/share/nautilus-python/extensions/")
# 7. Any questions?
If anything is not clear...
<br/>If you have a problem...
<br/>If you need a specific feature...
<br/>If any of your files is not supported...
<br/><b>...feel free to write a [GitHub issue](https://github.com/Lich-Corals/Nautilus-fileconverter-43/issues/new/choose)!</b>
# 7. Credits
# 8. Credits
## Authors
- [Linus Tibert](https://github.com/Lich-Corals)
Expand Down
69 changes: 43 additions & 26 deletions nautilus-fileconverter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --- Version number ---
converterVersion = "001002000" # Change the number if you want to trigger an update.
converterVersion = "001002001" # Change the number if you want to trigger an update.

# --- Imports ---
from gi.repository import Nautilus, GObject
Expand All @@ -12,6 +12,10 @@
import urllib.request
import json

# --- Get the path to the script and if it's writeable ---
currentPath = str(pathlib.Path(__file__).parent.resolve()) # used for config file and self-update!
scriptUpdateable = os.access(f"{currentPath}/{os.path.basename(__file__)}", os.W_OK)

# --- Check if dependencies are installed and imported ---
pyheifInstalled = False
jxlpyInstalled = False
Expand All @@ -21,28 +25,50 @@
pyheifInstalled = True
except ImportError:
pyheifInstalled = False
print(f"WARNING(Nautilus-file-converter): \"pyheif\" not found, if you want to convert from heif format, install the package using \"pip install pyheif\". See the readme on GitHub for more information." )
print(f"WARNING(Nautilus-file-converter)(000): \"pyheif\" not found, if you want to convert from heif format. View https://github.com/Lich-Corals/Nautilus-fileconverter-43/blob/main/README.md#6-warnings-and-errors for more information." )

try:
import jxlpy
from jxlpy import JXLImagePlugin
jxlpyInstalled = True
except ImportError:
jxlpyInstalled = False
print(f"WARNING(Nautilus-file-converter): \"jxlpy\" not found, if you want to convert from- or to jxl format, install the package using \"pip install jxlpy\". See the readme on GitHub for more information.")
print(f"WARNING(Nautilus-file-converter)(001): \"jxlpy\" not found, if you want to convert from- or to jxl format. View https://github.com/Lich-Corals/Nautilus-fileconverter-43/blob/main/README.md#6-warnings-and-errors for more information.")

if not scriptUpdateable:
print(f"WARNING(Nautilus-file-converter)(002): No permission to self-update; script at \"{currentPath}/{os.path.basename(__file__)}\" is not writeable. View https://github.com/Lich-Corals/Nautilus-fileconverter-43/blob/main/README.md#6-warnings-and-errors for more information.")

if not os.access(currentPath, os.W_OK):
print(f"WARNING(Nautilus-file-converter)(003): No permission to write configuration file; \"{currentPath}\" is not writeable. View https://github.com/Lich-Corals/Nautilus-fileconverter-43/blob/main/README.md#6-warnings-and-errors for more information.")

# --- Set default configs ---
_config = { # These are the pre-defined default settings; edit NFC43-Config.json if the program is installed in your home dictionary.
"automaticUpdates": True, # Replace the "True" with "False" if you don't want automatic updates.
"showPatchNotes": True, # Replace the "True" with "False" if you don't want to see patch notes.
"showPatchNoteButton": True, # Replace the "True" with "False" if you don't want the "View patch notes" button in the converter menu.
"showConfigHint": True, # Replace the "True" with "False" if you don't want to see the config hint.
"convertToSquares": True, # Replace the "True" with "False" if you don't want to convert to square formats.
"convertToWallpapers": True # Replace the "True" with "False" if you don't want to convert to wallpaper formats.
_configPreset = { # These are the pre-defined default settings; edit NFC43-Config.json if the program is installed in your home dictionary.
"automaticUpdates": True, # Replace the "True" with "False" if you don't want automatic updates.
"showPatchNotes": True, # Replace the "True" with "False" if you don't want to see patch notes.
"showPatchNoteButton": True, # Replace the "True" with "False" if you don't want the "View patch notes" button in the converter menu.
"showConfigHint": True, # Replace the "True" with "False" if you don't want to see the config hint.
"convertToSquares": True, # Replace the "True" with "False" if you don't want to convert to square formats.
"convertToWallpapers": True, # Replace the "True" with "False" if you don't want to convert to wallpaper formats.
"checkForDoubleInstallation": True # Replace the "True" with "False" if you don't the script to check if there is a second installation in another dictionary.
}

# --- Get the path to the script ---
currentPath = str(pathlib.Path(__file__).parent.resolve()) # used for config file and self-update!
# --- Load or store configs json ---
if scriptUpdateable:
if Path(f"{currentPath}/NFC43-Config.json").is_file():
with open(f"{currentPath}/NFC43-Config.json", 'r') as jsonFile:
try:
configJson = json.load(jsonFile)
except json.decoder.JSONDecodeError:
configJson = _configPreset
_config = configJson
for _setting in _configPreset:
if _setting not in _config:
_config[_setting] = _configPreset[_setting]
configJson = json.dumps(_config, indent=4)
else:
configJson = json.dumps(_configPreset, indent=4)
with open(f"{currentPath}/NFC43-Config.json", "w") as jsonFile:
jsonFile.write(configJson)

# --- Check for updates and update if auto-update is enabled ---
if _config["automaticUpdates"]:
Expand All @@ -53,28 +79,19 @@
print("Updating...")
if _config["showPatchNotes"]:
os.system(f"nohup xdg-open \"https://github.com/Lich-Corals/Nautilus-fileconverter-43/releases\" &")
if "/home/" in currentPath:
if scriptUpdateable:
fileUpdatePath = f"{currentPath}/{os.path.basename(__file__)}"
with open(fileUpdatePath, 'w') as file:
file.write(onlineFile)
else:
print("updating only supported in home!")

# --- Check for duplicate script if enabled ---
if _config["checkForDoubleInstallation"] and scriptUpdateable and os.path.isfile("/usr/share/nautilus-python/extensions/nautilus-fileconverter.py"):
print(f"WARNING(Nautilus-file-converter)(004): Double script installation detected. View https://github.com/Lich-Corals/Nautilus-fileconverter-43/blob/main/README.md#6-warnings-and-errors for more information.")

# --- Disable debug printing ---
# comment it out (using '#' in front of the line) if you wish debug printing
print = lambda *wish, **verbosity: None

# --- Load or store configs json ---
if "/home/" in currentPath:
if Path(f"{currentPath}/NFC43-Config.json").is_file():
with open(f"{currentPath}/NFC43-Config.json", 'r') as jsonFile:
configJson = json.load(jsonFile)
_config = configJson
else:
configJson = json.dumps(_config, indent=4)
with open(f"{currentPath}/NFC43-Config.json", "w") as jsonFile:
jsonFile.write(configJson)

# --- Create file format tuples and write format dict-lists? ---
class FileConverterMenuProvider(GObject.GObject, Nautilus.MenuProvider):
READ_FORMATS_IMAGE = ('image/jpeg',
Expand Down

0 comments on commit 19b080a

Please sign in to comment.