jiri-otoupal / pycrosskit Goto Github PK
View Code? Open in Web Editor NEWPython Cross Platform Toolkit for Windows and Linux Environment Variables, Shortcuts and Start Menu Shortcuts
License: MIT License
Python Cross Platform Toolkit for Windows and Linux Environment Variables, Shortcuts and Start Menu Shortcuts
License: MIT License
Im trying to create a shortcut to "C:\Program Files (x86)\Slay\Slay.exe" (Slay being the name of my program)
But on running the following code
from pycrosskit.shortcuts import Shortcut
Shortcut(shortcut_name="Slay", exec_path="C:\\Program Files (x86)\\Slay\\Slay.exe", description="Slay",
icon_path="C:\\Program Files (x86)\\Slay\\icon.ico", work_dir="C:\\Program Files (x86)\\Slay", desktop=True, start_menu=False)
What happens is that it creates a shortcut with the execution target set to
"C:\Program Files (x86)\Slay\Slay.exe" Files(x86)\Slay\Slay.exe
Whereas I would want
"C:\Program Files (x86)\Slay\Slay.exe"
Running on windows 11 python 3.10.6
Describe the bug
The start_menu and desktop parameters get switched in different functions depending on your platform
i.e specifying start_menu=True in create_shortcut would cause a desktop shortcut to be made and not a start_menu shortcut
Additional context
Within the code, the order of the parameters in the function definition is different from that in which they are passed to said function
this is true for create_shortcut() on linux
and for delete_shortcut() on desktop
Moreover since this affects the path returned to testing code, this was not caught in the tests
It always uses the ~/.bashrc
no matter what argument I provide.
Hi @jiri-otoupal,
Thanks for your small but useful package.
Is there any particular reason not to follow Semver, the recommended convention for Python packages?
Describe the bug
Pycrosskit hardcodes winreg values in windows.py
to HKEY_CURRENT_USER
. However, I'm looking to override that value HKEY_CURRENT_SYSTEM
to get access to system environment variables. Without digging through the source code to override windows.py
, this results in retrieving those variables from user env rather than system env as it errors out in __get_policy_key_readonly
function.
To Reproduce
Setting the following reg_path to get values when retrieving from SysEnv().get(key,reg_path, registry)
will result in error
reg_path = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
SysEnv().get(key="Path", reg_path=reg_path, registry=True)
Snippet from windows.py
example of hardcoding
@classmethod
def __get_policy_key_readonly(cls, reg_path: str):
root = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
policy_key = winreg.OpenKeyEx(root, reg_path)
return policy_key, root
Expected behavior
I'm trying to use Pycross kit to get system environment variables instead of using the winreg implementation which works as follows:
import winreg
reg_path = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path)
system_environment_variables = winreg.QueryValueEx(reg_key, 'Path')[0]
propose to change windows.py
to the following to allow override in values for reg_key and set winreg.HKEY_CURRENT_USER
as default to not change any current behavior
@classmethod
def __get_policy_key_readonly(cls, reg_path: str, reg_key = winreg.HKEY_CURRENT_USER):
root = winreg.ConnectRegistry(None, reg_key)
policy_key = winreg.OpenKeyEx(root, reg_path)
return policy_key, root
@classmethod
def set(
cls,
key,
value,
subkey="",
reg_path=r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
reg_key=winreg.HKEY_CURRENT_USER,
registry=True,
silent=False,
):
"""
Set Environment Variable
:param silent: If permission error should fail silently
:param key: Variable Name
:param value: Variable Value
:param subkey: Sub-Key under key ( like file in folder )
:param reg_path: Register path for windows
:param reg_key: WinReg register key for windows
:param registry: Only for windows, if true variable is set to registry path
if false, variable is set to environment variables
"""
if registry:
root = winreg.ConnectRegistry(None, reg_key)
Desktop (please complete the following information):
Hi @jiri-otoupal, I noticed the CI is failing for publishing packages on main. I would like the use the latest changes. Would it be possible to get a release soon?
Thanks,
Hi @jiri-otoupal, quick question - does this package currently support the latest Python 3.11?
I tried this package and when within python console I get an error that default_reg_path is not defined on the get_var example.
I am on Win 10.
Should the example be updated to make it work?
The examples should at least be extended with this line of code:
from pycrosskit.envariables import SysEnv
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.