natlinkcore 5.4.2.dev5__tar.gz → 5.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. natlinkcore-5.4.3/LICENSE +190 -0
  2. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/PKG-INFO +13 -4
  3. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/pyproject.toml +7 -3
  4. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/readme.md +8 -0
  5. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/config.py +73 -47
  6. natlinkcore-5.4.3/src/natlinkcore/configure/natlink_extract_ini_value.py +50 -0
  7. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/natlinkconfig_cli.py +191 -27
  8. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/natlinkconfigfunctions.py +88 -40
  9. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/loader.py +9 -2
  10. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/natlinkstatus.py +3 -3
  11. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/natlinkutils.py +6 -1
  12. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/DefaultConfig/_config_instructions.py +0 -0
  13. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/DefaultConfig/_information_config.py +0 -0
  14. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/DefaultConfig/natlink.ini +0 -0
  15. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/Index.htm +0 -0
  16. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_globals.py +0 -0
  17. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_mouse.py +0 -0
  18. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_repeatthat.py +0 -0
  19. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample1.py +0 -0
  20. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample2.py +0 -0
  21. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample3.py +0 -0
  22. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample4.py +0 -0
  23. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample5.py +0 -0
  24. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample8.py +0 -0
  25. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sample9.py +0 -0
  26. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/_sleeping.py +0 -0
  27. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/excel_sample7.py +0 -0
  28. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/natspeak_sample6.py +0 -0
  29. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/trainuser.py +0 -0
  30. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/transcribe.py +0 -0
  31. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/wiki.css +0 -0
  32. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/windict.py +0 -0
  33. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/winspch.py +0 -0
  34. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/winword_styles_sample.py +0 -0
  35. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/OriginalSampleMacros/wordpad.py +0 -0
  36. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/__init__.py +0 -0
  37. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_debug_natlink.py +0 -0
  38. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample7.py +0 -0
  39. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample_activatedeactivate.py +0 -0
  40. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample_callback.py +0 -0
  41. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample_directory_information.py +0 -0
  42. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample_move_natlinktimer.py +0 -0
  43. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample_natlinkstatus.py +0 -0
  44. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_sample_runmimic.py +0 -0
  45. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/SampleMacros/_samplehypothesis.py +0 -0
  46. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/__init__.py +0 -0
  47. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/_natlink_core.pyi +0 -0
  48. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/callbackhandler.py +0 -0
  49. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/README.md +0 -0
  50. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/__init__.py +0 -0
  51. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/foo.txt +0 -0
  52. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/list of functions.txt +0 -0
  53. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/loggert.py +0 -0
  54. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/natlink_extensions.py +0 -0
  55. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/configure/natlinkconfig_gui.py +0 -0
  56. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/gramparser.py +0 -0
  57. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/natlink.pyi +0 -0
  58. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/natlinkpydebug.py +0 -0
  59. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/natlinktimer.py +0 -0
  60. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/nsformat.py +0 -0
  61. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/py.typed +0 -0
  62. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/readwritefile.py +0 -0
  63. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/redirect_output.py +0 -0
  64. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/singleton.py +0 -0
  65. {natlinkcore-5.4.2.dev5 → natlinkcore-5.4.3}/src/natlinkcore/tkinter_dialogs.py +0 -0
@@ -0,0 +1,190 @@
1
+ NatLink
2
+ (c) Copyright 1997-1999 by Joel Gould.
3
+ Portions (c) Copyright 1997-1999 by Dragon Systems,
4
+ Inc. All Rights Reserved. Permission to use, copy, modify and
5
+ distribute this software (except for the files noted below) and
6
+ documentation for any purpose and without fee is hereby granted,
7
+ provided that this copyright notice appear in all copies and
8
+ that both the copyright notice and this permission notice appear
9
+ in supporting documentation, and that the name Joel Gould not be
10
+ used in advertising or publicity pertaining to distribution of
11
+ the software without specific, written permission.
12
+
13
+ The following files are NOT covered by the previous previous
14
+ paragraph: NatlinkSource\speech.h and
15
+ NatlinkSource\dspeech.h. These files may not be redistributed
16
+ although they can be freely downloaded from
17
+ http://www.synapseadaptive.com/joel/PythonMacroSystem.html and
18
+ used on one machine.
19
+
20
+ Joel Gould disclaim all warranties with regard to this software,
21
+ including all implied warranties of merchantability and fitness,
22
+ in no event shall Joel Gould be liable for any special, indirect
23
+ or consequential damages or any damages whatsoever resulting
24
+ from the loss of use, data or profits whether in an action of
25
+ contract, negligence or tortious action, arising out of
26
+ connection with the use or performance of this software.
27
+ Possession of this software does NOT grant the possessor any
28
+ license to Dragon NaturallySpeaking or any other Dragon Systems
29
+ product, except where license to Dragon NaturallySpeaking or any
30
+ other Dragon Systems products is purchased or otherwise obtained
31
+ separately. This copyright only applies to NatLink, including
32
+ source and object code and not to Dragon NaturallySpeaking or
33
+ any other Dragon Systems product. Software on this web site is
34
+ not available from Dragon Systems, nor is Dragon Systems
35
+ formally associated with this software in any way.
36
+
37
+ -----------------------------------
38
+
39
+ Vocola
40
+ Copyright (c) 2002-2012 by Rick Mohr
41
+
42
+ Portions Copyright (c) 2012-15 by Hewlett-Packard Development
43
+ Company, L.P.
44
+
45
+ Permission is hereby granted, free of charge, to any person
46
+ obtaining a copy of this software and associated documentation
47
+ files (the "Software"), to deal in the Software without
48
+ restriction, including without limitation the rights to use,
49
+ copy, modify, merge, publish, distribute, sublicense, and/or
50
+ sell copies of the Software, and to permit persons to whom the
51
+ Software is furnished to do so, subject to the following
52
+ conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
59
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
60
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
61
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
62
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
63
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
64
+ OTHER DEALINGS IN THE SOFTWARE.
65
+
66
+ -----------------------------------
67
+
68
+ Configurenatlinkunimacrovocola:
69
+ Copyright (c) 2008 by Quintijn Hoogenboom. It may be
70
+ redistributed in any way as long as this copyright notice
71
+ remains.
72
+
73
+ -----------------------------------
74
+
75
+ Unimacro (c) 2002-2011 Quintijn Hoogenboom, Ben Staniford, Bart Jan
76
+ van Os 2011 Frank Olaf Sem-Jacobsen
77
+
78
+ "unimacro" is free software; you can redistribute it
79
+ and/or modify it under the terms of the GNU General
80
+ Public License, see: http://www.gnu.org/licenses/gpl.txt
81
+
82
+ "unimacro" is distributed in the hope that it will be
83
+ useful, but WITHOUT ANY WARRANTY; See the GNU General
84
+ Public License details.
85
+
86
+ "unimacro" makes use of another SourceForge project "natlink",
87
+ which has the copyright notice shown above.
88
+
89
+ -----------------------------------
90
+
91
+ ConfigureNatLink.exe NLVCSetup.msi MessageWindow.dll
92
+ Copyright (c) 2004-2005 Applied Recognition Inc. All rights
93
+ reserved.
94
+
95
+ You may freely obtain this software from
96
+ http://speechwiki.org/NL.HomePage
97
+
98
+ Unauthorized redistribution, reverse engineering, and
99
+ decompilation is prohibited.
100
+
101
+ The Software comes "as is", with no warranties. None
102
+ whatsoever. This means no express, implied or statutory
103
+ warranty, including without limitation, warranties of
104
+ merchantability or fitness for a particular purpose or any
105
+ warranty of title or non-infringement.
106
+
107
+ Neither Applied Recognition Inc. nor any contributor to the
108
+ Software will be liable for any of those types of damages known
109
+ as indirect, special, consequential, or incidental related to
110
+ the Software or this license, to the maximum extent the law
111
+ permits, no matter what legal theory it's based on.
112
+
113
+
114
+ -----------------------------------
115
+
116
+ Shared Source License for Microsoft Visual Basic Power Pack for
117
+ Microsoft Visual Basic 2003
118
+
119
+ This license governs use of the accompanying software
120
+ (`Software'), and your use of the Software constitutes acceptance
121
+ of this license.
122
+
123
+ You may use the Software for any commercial or noncommercial purpose,
124
+ including distributing derivative works.
125
+
126
+ In return, we simply require that you agree:
127
+
128
+ 1. Not to remove any copyright or other notices from the Software.
129
+
130
+ 2. That if you distribute the Software in source code form you do so
131
+ only under this license (i.e. you must include a complete copy of
132
+ this license with your distribution), and if you distribute the
133
+ Software solely in object form you only do so under a license that
134
+ complies with this license.
135
+
136
+ 3. That the Software comes "as is", with no warranties. None
137
+ whatsoever. This means no express, implied or statutory warranty,
138
+ including without limitation, warranties of merchantability or
139
+ fitness for a particular purpose or any warranty of title or
140
+ non-infringement. Also, you must pass this disclaimer on whenever you
141
+ distribute the Software or derivative works.
142
+
143
+ 4. That neither Microsoft nor any contributor to the Software will be
144
+ liable for any of those types of damages known as indirect, special,
145
+ consequential, or incidental related to the Software or this license,
146
+ to the maximum extent the law permits, no matter what legal theory
147
+ it's based on. Also, you must pass this limitation of liability on
148
+ whenever you distribute the Software or derivative works.
149
+
150
+ 5. That if you sue anyone over patents that you think may apply to the
151
+ Software for a person's use of the Software, your license to the
152
+ Software ends automatically.
153
+
154
+ 6. That the patent rights, if any, granted in this license only apply to
155
+ the Software, not to any derivative works you make.
156
+
157
+ 7. That the Software is subject to U.S. export jurisdiction at the time
158
+ it is licensed to you, and it may be subject to additional export or
159
+ import laws in other places. You agree to comply with all such laws
160
+ and regulations that may apply to the Software after delivery of the
161
+ software to you.
162
+
163
+ 8. That if you are an agency of the U.S. Government, (i) Software
164
+ provided pursuant to a solicitation issued on or after December 1,
165
+ 1995, is provided with the commercial license rights set forth in
166
+ this license, and (ii) Software provided pursuant to a solicitation
167
+ issued prior to December 1, 1995, is provided with `Restricted
168
+ Rights' as set forth in FAR, 48 C.F.R. 52.227-14 (June 1987) or DFAR,
169
+ 48 C.F.R. 252.227-7013 (Oct 1988), as applicable.
170
+
171
+ 9. That your rights under this License end automatically if you breach
172
+ it in any way.
173
+
174
+ 10. That all rights not expressly granted to you in this license are
175
+ reserved.
176
+
177
+ ---------------------------------------
178
+
179
+
180
+ XPCommonControls.dll
181
+ From http://www.steepvalley.net
182
+
183
+ The controls plus the source code are completely free to use. There are
184
+ no cost at all attached to this project.
185
+
186
+ This means also that I cannot take any responsibility for bugs and
187
+ errors resulting from this code.
188
+
189
+
190
+ ----------------------------
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: natlinkcore
3
- Version: 5.4.2.dev5
3
+ Version: 5.4.3
4
4
  Summary: Python portion of Natlink, a compatibility module for Dragon Naturally Speaking
5
5
  Author-email: "Quintijn Hoogenboom (maintainer)" <q.hoogenboom@antenna.nl>
6
6
  Requires-Python: >=3.10
@@ -13,11 +13,12 @@ Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: Implementation :: CPython
14
14
  Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
15
15
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ License-File: LICENSE
16
17
  Requires-Dist: FreeSimpleGUI>=5.1.0
17
18
  Requires-Dist: pydebugstring >= 1.0.0.1
18
- Requires-Dist: dtactions ~= 1.6.4.dev3
19
+ Requires-Dist: dtactions >= 1.6.4.dev3
19
20
  Requires-Dist: platformdirs >= 4.2.0
20
- Requires-Dist: natlink ~= 5.5.8.dev2
21
+ Requires-Dist: natlink >= 5.5.7
21
22
  Requires-Dist: pyenvutils ; extra == "dev"
22
23
  Requires-Dist: entry-point-inspector ; extra == "dev"
23
24
  Requires-Dist: build ; extra == "dev"
@@ -39,6 +40,14 @@ You can install from [The Python Package Index (PyPI)](https://pypi.org/) with
39
40
 
40
41
  Note that natlinkcore will not install if you have not installed Natlink first. Natlink is installed through running an installer.
41
42
 
43
+ This will install utilties you can run from a shell prompt: natlinkconfig_cli, natlinkconfig_gui, and natlink_extract_ini_value.
44
+
45
+ You can use natlink_extract_ini_value to grab a directory or setting out of natlink.ini for copying and pasting or a shell script.
46
+ ```
47
+ PS C:\Users\doug\code\dt\natlinkcore> natlink_extract_ini_value -s directories -k dragonflyuserdirectory
48
+ C:\Users\doug\Documents
49
+ ```
50
+
42
51
 
43
52
  ## Test Framework
44
53
  Tests use the [pytest](https://docs.pytest.org/) framework.
@@ -5,7 +5,9 @@ build-backend = "flit_core.buildapi"
5
5
  [project]
6
6
  name = "natlinkcore"
7
7
  authors = [{name = "Quintijn Hoogenboom (maintainer)", email = "q.hoogenboom@antenna.nl"}]
8
- version="5.4.2.dev5"
8
+
9
+ version="5.4.3"
10
+
9
11
  dynamic = [ "description"]
10
12
  requires-python = ">=3.10"
11
13
  readme = "readme.md"
@@ -13,9 +15,10 @@ dependencies= [
13
15
 
14
16
  "FreeSimpleGUI>=5.1.0",
15
17
  "pydebugstring >= 1.0.0.1",
16
- "dtactions ~= 1.6.4.dev3",
18
+ "dtactions >= 1.6.4.dev3",
17
19
  "platformdirs >= 4.2.0",
18
- "natlink ~= 5.5.8.dev2"
20
+ "natlink >= 5.5.7"
21
+ # "natlink >= 5.5.8.dev2"
19
22
  ]
20
23
  classifiers=[
21
24
  "Development Status :: 4 - Beta",
@@ -54,6 +57,7 @@ testpaths= [
54
57
  [project.scripts]
55
58
  natlinkconfig_cli = "natlinkcore.configure.natlinkconfig_cli:main_cli"
56
59
  natlink_extensions = "natlinkcore.configure.natlink_extensions:main"
60
+ natlink_extract_ini_value = "natlinkcore.configure.natlink_extract_ini_value:main"
57
61
 
58
62
  [project.gui-scripts]
59
63
  natlinkconfig_gui = "natlinkcore.configure.natlinkconfig_gui:main_gui"
@@ -11,6 +11,14 @@ You can install from [The Python Package Index (PyPI)](https://pypi.org/) with
11
11
 
12
12
  Note that natlinkcore will not install if you have not installed Natlink first. Natlink is installed through running an installer.
13
13
 
14
+ This will install utilties you can run from a shell prompt: natlinkconfig_cli, natlinkconfig_gui, and natlink_extract_ini_value.
15
+
16
+ You can use natlink_extract_ini_value to grab a directory or setting out of natlink.ini for copying and pasting or a shell script.
17
+ ```
18
+ PS C:\Users\doug\code\dt\natlinkcore> natlink_extract_ini_value -s directories -k dragonflyuserdirectory
19
+ C:\Users\doug\Documents
20
+ ```
21
+
14
22
 
15
23
  ## Test Framework
16
24
  Tests use the [pytest](https://docs.pytest.org/) framework.
@@ -143,7 +143,7 @@ class NatlinkConfig:
143
143
  # should not happen, because of DefaultConfig (was InstallTest)
144
144
  raise NoGoodConfigFoundException('No natlink config file found, please run configure natlink program\n\t(***configurenatlink***)')
145
145
 
146
- def expand_path(input_path: str) -> str:
146
+ def expand_path(input_dir: str, must_exist: bool = True) -> str:
147
147
  r"""expand path if it starts with "~" or starts with an environment variable or name of python package
148
148
 
149
149
  Paths can be:
@@ -154,77 +154,103 @@ Paths can be:
154
154
  - Obsolete: natlink_userdir/...: instead natlink_settingsdir will be searched for, and a message is thrown. In the config program things are checked more thoroughly.
155
155
  - some other environment variable: this environment variable is expanded
156
156
 
157
+
158
+ must_exist:
159
+ default: True, the expanded path should exist.
160
+ If not (possibly when in natlinkconfigfunctions a directory should be created), pass False
161
+
157
162
  The Documents directory can be found by "~\Documents"...
158
163
 
159
164
  When there is nothing to expand, just return the input
160
165
  """
161
- expanduser, expandvars, normpath, isdir = os.path.expanduser, os.path.expandvars, os.path.normpath, os.path.isdir
166
+ expanduser, expandvars, normpath, isdir, join = os.path.expanduser, os.path.expandvars, os.path.normpath, os.path.isdir, os.path.join
162
167
 
163
- # I think, this is tackled below, input_path is one word, without slashes or ~ or %(...) (QH)
168
+ # I think, this is tackled below, input_dir is one word, without slashes or ~ or %(...) (QH)
164
169
  # try:
165
- # package_spec=u.find_spec(input_path)
170
+ # package_spec=u.find_spec(input_dir)
166
171
  # if package_spec is not None:
167
172
  # package_path=str(p.Path(package_spec.origin).parent)
168
173
  # return normpath(package_path)
169
174
  # except:
170
175
  # pass
171
- if input_path.startswith('~'):
176
+ if input_dir.startswith('~'):
172
177
  home = expanduser('~')
173
- env_expanded = home + input_path[1:]
174
- # print(f'expand_path: "{input_path}" include "~": expanded: "{env_expanded}"')
175
- return normpath(env_expanded)
178
+ home_expanded = home + input_dir[1:]
179
+ # print(f'expand_path: "{input_dir}" include "~": expanded: "{env_expanded}"')
180
+ if must_exist:
181
+ assert isdir(home_expanded)
182
+ return normpath(home_expanded)
183
+
184
+ if isdir(input_dir):
185
+ return normpath(input_dir)
186
+
187
+ # split in trunk and rest:
188
+ if input_dir.find('/') > 0:
189
+ trunk, rest = input_dir.split('/', 1)
190
+ elif input_dir.find('\\') > 0:
191
+ trunk, rest = input_dir.split('\\', 1)
192
+ else:
193
+ trunk, rest = input_dir, ''
176
194
 
177
195
  ## "natlink_userdir" will go obsolete, to be replaced with "natlink_settingsdir" below:
178
- if input_path.startswith('natlink_userdir/') or input_path.startswith('natlink_userdir\\'):
179
- nud = expand_natlink_settingsdir()
180
- if isdir(nud):
181
- dir_path = input_path.replace('natlink_userdir', nud)
182
- dir_path = normpath(dir_path)
183
- if isdir(dir_path):
184
- return dir_path
185
- print(f'no valid directory found with "natlink_userdir": "{dir_path}"\nbut "natlink_userdir" should be replaced by "natlink_settingsdir" anyway')
186
- return dir_path
187
- print(f'natlink_userdir does not expand to a valid directory: "{nud}"\nbut "natlink_userdir" should be replaced by "natlink_settingsdir" anyway')
188
- return normpath(nud)
189
-
190
- if input_path.startswith('natlink_settingsdir/') or input_path.startswith('natlink_settingsdir\\'):
196
+ if trunk == 'natlink_userdir':
197
+ trunk = expand_natlink_settingsdir()
198
+ if isdir(trunk):
199
+ replaced_dir = join(trunk, rest)
200
+ if must_exist:
201
+ if isdir(replaced_dir):
202
+ return normpath(replaced_dir)
203
+ else:
204
+ print(f'no valid directory found with "natlink_userdir": "{input_dir}"\nbut "natlink_userdir" should be replaced by "natlink_settingsdir" anyway')
205
+ return ''
206
+ # must exist False:
207
+ return replaced_dir
208
+ # trunk is NOT a directory:
209
+ print(f'no valid directory found with "natlink_userdir": "{trunk}"\nbut "natlink_userdir" should be replaced by "natlink_settingsdir" anyway')
210
+ return ''
211
+
212
+ if trunk == 'natlink_settingsdir':
191
213
  nsd = expand_natlink_settingsdir()
192
- if isdir(nsd):
193
- dir_path = input_path.replace('natlink_settingsdir', nsd)
194
- dir_path = normpath(dir_path)
195
- if isdir(dir_path):
196
- return dir_path
197
- print(f'no valid directory found with "natlink_settingsdir": "{dir_path}"')
198
- return dir_path
199
- print(f'natlink_settingsdir does not expand to a valid directory: "{nsd}"')
200
- return normpath(nsd)
201
-
214
+ if not isdir(nsd):
215
+ print(f'natlink_settingsdir does not expand to a valid directory: "{nsd}" (input_dir: "{input_dir}"')
216
+ return ''
217
+
218
+ replaced_dir = normpath(join(nsd, rest))
219
+ if isdir(replaced_dir):
220
+ return replaced_dir
221
+ if must_exist:
222
+ return ''
223
+ return replaced_dir
202
224
 
203
225
  # try if package:
204
- if input_path.find('/') > 0:
205
- package_trunk, rest = input_path.split('/', 1)
206
- elif input_path.find('\\') > 0:
207
- package_trunk, rest = input_path.split('\\', 1)
208
- else:
209
- package_trunk, rest = input_path, ''
210
- # find path for package. not an alternative way without loading the package is to use importlib.util.findspec.
226
+ # find path for package. not an alternative way without loading the package is to use importlib.util.findspec.
211
227
 
212
228
  # first check for exclude "C:" as trunk:
213
- if package_trunk and package_trunk[-1] != ":":
229
+ if trunk and trunk[-1] != ":":
214
230
  try:
215
- pack = __import__(package_trunk)
231
+ pack = __import__(trunk)
216
232
  package_path = pack.__path__[-1]
217
- if rest:
218
- dir_expanded = str(Path(package_path)/rest)
219
- return dir_expanded
220
- return package_path
233
+ replaced_dir = join(package_path, rest)
234
+ if isdir(replaced_dir):
235
+ return replaced_dir
236
+ if not must_exist:
237
+ return replaced_dir
221
238
 
222
239
  except (ModuleNotFoundError, OSError):
223
240
  pass
224
241
 
225
- env_expanded = expandvars(input_path)
226
- # print(f'env_expanded: "{env_expanded}", from envvar: "{input_path}"')
227
- return normpath(env_expanded)
242
+
243
+ # if here: try if there are extenden environment variables to expand:
244
+ env_expanded = expandvars(input_dir)
245
+ # print(f'env_expanded: "{env_expanded}", from envvar: "{input_dir}"')
246
+ env_expanded = normpath(env_expanded)
247
+ if isdir(env_expanded):
248
+ return env_expanded
249
+
250
+ if not must_exist:
251
+ return env_expanded
252
+ # no valid path, but MUST exist (default)
253
+ return ''
228
254
 
229
255
  def expand_natlink_settingsdir():
230
256
  """Return the location of the natlink config files
@@ -0,0 +1,50 @@
1
+ import argparse
2
+ import sys
3
+ from natlinkcore.configure.natlinkconfigfunctions import NatlinkConfig
4
+ import configparser
5
+ from pathlib import Path
6
+ import configparser
7
+
8
+ def get_config_value(config, section, key):
9
+ if not config.has_section(section):
10
+ raise configparser.NoSectionError(section)
11
+ if not config.has_option(section, key):
12
+ raise configparser.NoOptionError(key, section)
13
+ return config.get(section, key)
14
+
15
+ def main():
16
+ parser = argparse.ArgumentParser(description=
17
+ f"""prints the value for the key in the section of natlink.ini to standard out. You can also ask for the full path to the ini file.
18
+ for example, to get the dragonflyuserdirectory key in the directories section:
19
+ {sys.argv[0]} --section 'directories' --key dragonflyuserdirectory
20
+ """)
21
+ parser.add_argument('-i', "--ini_file",action='store_true', help='print the full path to the natlink.ini file')
22
+
23
+
24
+
25
+ parser.add_argument('-s', '--section', type=str, help='Section name')
26
+ parser.add_argument('-k', '--key', type=str, help='Key name')
27
+
28
+ args = parser.parse_args()
29
+
30
+
31
+ try:
32
+ config=NatlinkConfig()
33
+ config_path=config.natlinkconfig_path
34
+ config_file=Path(config_path)/"natlink.ini"
35
+ if args.ini_file:
36
+ print(config_file)
37
+ exit(0)
38
+ if not (args.key and args.section):
39
+ raise Exception("Must supply key and section or -i/--ini_file")
40
+ config=configparser.ConfigParser()
41
+ config.read(config_file)
42
+ v=get_config_value(config,args.section,args.key)
43
+ print(f"{v}")
44
+ except Exception as e:
45
+ print(e)
46
+ exit(-1)
47
+
48
+
49
+ if __name__ == "__main__":
50
+ main()