Skip to content

Instantly share code, notes, and snippets.

@davidlatwe
Created February 8, 2022 19:03
Show Gist options
  • Save davidlatwe/27359c4dd9f348298fb84261b1adb1c5 to your computer and use it in GitHub Desktop.
Save davidlatwe/27359c4dd9f348298fb84261b1adb1c5 to your computer and use it in GitHub Desktop.
Index: src/rezplugins/shell/_utils/powershell_base.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py
--- a/src/rezplugins/shell/_utils/powershell_base.py (revision d392c65bf63b4bca8106f938cec49144ba54e770)
+++ b/src/rezplugins/shell/_utils/powershell_base.py (date 1644346789393)
@@ -88,26 +88,14 @@
cls.syspaths = config.standard_system_paths
return cls.syspaths
- # detect system paths using registry
- def gen_expected_regex(parts):
- whitespace = r"[\s]+"
- return whitespace.join(parts)
-
# TODO: Research if there is an easier way to pull system PATH from
# registry in powershell
paths = []
cmd = [
- "REG", "QUERY",
- ("HKLM\\SYSTEM\\CurrentControlSet\\"
- "Control\\Session Manager\\Environment"), "/v", "PATH"
+ "powershell",
+ '(Get-ItemProperty "HKLM:SYSTEM/CurrentControlSet/Control/Session Manager/Environment").Path',
]
-
- expected = gen_expected_regex([
- ("HKEY_LOCAL_MACHINE\\\\SYSTEM\\\\CurrentControlSet\\\\"
- "Control\\\\Session Manager\\\\Environment"), "PATH",
- "REG_(EXPAND_)?SZ", "(.*)"
- ])
p = Popen(cmd, stdout=PIPE, stderr=PIPE,
shell=True, text=True)
@@ -115,16 +103,9 @@
out_ = out_.strip()
if p.returncode == 0:
- match = re.match(expected, out_)
- if match:
- paths.extend(match.group(2).split(os.pathsep))
+ paths.extend(out_.split(os.pathsep))
- cmd = ["REG", "QUERY", "HKCU\\Environment", "/v", "PATH"]
-
- expected = gen_expected_regex([
- "HKEY_CURRENT_USER\\\\Environment", "PATH", "REG_(EXPAND_)?SZ",
- "(.*)"
- ])
+ cmd = ["powershell", "(Get-ItemProperty -Path HKCU:Environment).Path"]
p = Popen(cmd, stdout=PIPE, stderr=PIPE,
shell=True, text=True)
@@ -132,9 +113,7 @@
out_ = out_.strip()
if p.returncode == 0:
- match = re.match(expected, out_)
- if match:
- paths.extend(match.group(2).split(os.pathsep))
+ paths.extend(out_.split(os.pathsep))
cls.syspaths = [x for x in paths if x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment