How should a gramplet validate a (local, network, internet) file path string?

Has the Gramps-Project approved a standard process for path validation, evaluation and verification?

Does it identify whether a string was intended to be a URL, URI or internal relative reference? Then does it evaluate Gramps or OS specific Environment Variables? Then does it validate that the string is a legal form? Then does it verify that the resource is accessible with the current system without attempting to open the resource?

pathvalidate

Summary
    Features
Examples
    Sanitize a filename
    Sanitize a filepath
    Validate a filename
    Check a filename
    filename/filepath validator for argparse
    filename/filepath sanitizer for argparse
    filename/filepath validator for click
    filename/filepath sanitizer for click
    For more information
Installation
    Installation: pip
    Installation: conda
    Installation: apt
Dependencies
Documentation
Sponsors

Use os.path.expandvars to expand the environment variables in the string, for example:

os.path.expandvars(‘$C/test/testing’)
‘/stackoverflow/test/testing’

There’s little interest in switching Gramps from the Gtk File Chooser to native choosers (for macOS and Windows) in order to merely have a more native appearance and UX. But perhaps some of the filesystem idiosyncrasies could be supported?

Gramps has https://github.com/gramps-project/gramps/blob/master/aio/grampsaiocd.py

It appears that the only MS Windows Environment Variable that Gramps supports parsing is the %path%. The others in this python file are specific to Gramps.

Could support for other M$ Environmental Variable typical file locations? :

  • %APPDATA%
  • %LOCALAPPDATA%
  • %Public%
  • %SystemDrive%
  • %TEMP%
  • %TMP%
  • %USERNAME%
  • %USERPROFILE%

It’s important to note that the os.getenv() function can also be used to retrieve environment variables. This function returns None if the variable does not exist, while os.environ['MyValue'] raises a KeyError exception when the variable does not exist.

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\user\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=DESKTOP-S9JVIUA
ComSpec=C:\WINDOWS\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
FPS_BROWSER_USER_PROFILE_STRING=Default
HOMEDRIVE=C:
HOMEPATH=\Users\user
LOCALAPPDATA=C:\Users\user\AppData\Local
LOGONSERVER=\\WIN-R8FH6JKVCN7
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\user\AppData\Local\Microsoft\WindowsApps;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=8e09
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\Users\user\AppData\Local\Temp
TMP=C:\Users\user\AppData\Local\Temp
USERDOMAIN=DESKTOP-S9JVIUA
USERDOMAIN_ROAMINGPROFILE=DESKTOP-S9JVIUA
USERNAME=user
USERPROFILE=C:\Users\user
windir=C:\WINDOWS
ZES_ENABLE_SYSMAN=1