rda-python-common 2.1.8__tar.gz → 2.1.10__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 (34) hide show
  1. {rda_python_common-2.1.8/src/rda_python_common.egg-info → rda_python_common-2.1.10}/PKG-INFO +2 -2
  2. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/README.md +1 -1
  3. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/pyproject.toml +4 -1
  4. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/__init__.py +1 -1
  5. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_cmd.py +7 -1
  6. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_log.py +12 -7
  7. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pgpassword.py +24 -19
  8. rda_python_common-2.1.10/src/rda_python_common/pgpassword.usg +57 -0
  9. {rda_python_common-2.1.8 → rda_python_common-2.1.10/src/rda_python_common.egg-info}/PKG-INFO +2 -2
  10. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common.egg-info/SOURCES.txt +1 -0
  11. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/LICENSE +0 -0
  12. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/setup.cfg +0 -0
  13. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgCMD.py +0 -0
  14. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgDBI.py +0 -0
  15. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgFile.py +0 -0
  16. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgLOG.py +0 -0
  17. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgLock.py +0 -0
  18. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgOPT.py +0 -0
  19. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgSIG.py +0 -0
  20. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgSplit.py +0 -0
  21. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/PgUtil.py +0 -0
  22. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_dbi.py +0 -0
  23. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_file.py +0 -0
  24. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_lock.py +0 -0
  25. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_opt.py +0 -0
  26. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_password.py +0 -0
  27. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_sig.py +0 -0
  28. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_split.py +0 -0
  29. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common/pg_util.py +0 -0
  30. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common.egg-info/dependency_links.txt +0 -0
  31. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common.egg-info/entry_points.txt +0 -0
  32. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common.egg-info/requires.txt +0 -0
  33. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/src/rda_python_common.egg-info/top_level.txt +0 -0
  34. {rda_python_common-2.1.8 → rda_python_common-2.1.10}/test/test_common.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rda_python_common
3
- Version: 2.1.8
3
+ Version: 2.1.10
4
4
  Summary: RDA Python common library codes shared by other RDA python packages
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-common
@@ -92,7 +92,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN)
92
92
  python -c "import rda_python_common; print(rda_python_common.__version__)"
93
93
  ```
94
94
 
95
- You should see the installed version (currently `2.1.8`). If the import
95
+ You should see the installed version (currently `2.1.10`). If the import
96
96
  fails, double-check that the active Python environment is the one where you
97
97
  ran `pip install`.
98
98
 
@@ -72,7 +72,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN)
72
72
  python -c "import rda_python_common; print(rda_python_common.__version__)"
73
73
  ```
74
74
 
75
- You should see the installed version (currently `2.1.8`). If the import
75
+ You should see the installed version (currently `2.1.10`). If the import
76
76
  fails, double-check that the active Python environment is the one where you
77
77
  ran `pip install`.
78
78
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rda_python_common"
7
- version = "2.1.8"
7
+ version = "2.1.10"
8
8
  authors = [
9
9
  { name="Zaihua Ji", email="zji@ucar.edu" },
10
10
  ]
@@ -33,5 +33,8 @@ pythonpath = [
33
33
  "src"
34
34
  ]
35
35
 
36
+ [tool.setuptools.package-data]
37
+ rda_python_common = ["*.usg"]
38
+
36
39
  [project.scripts]
37
40
  pgpassword = "rda_python_common.pgpassword:main"
@@ -22,7 +22,7 @@ object that existing callers expect.
22
22
 
23
23
  from . import PgLOG, PgUtil, PgDBI, PgFile, PgLock, PgCMD, PgSIG, PgOPT, PgSplit
24
24
 
25
- __version__ = "2.1.8"
25
+ __version__ = "2.1.10"
26
26
 
27
27
  __all__ = [
28
28
  "PgLOG",
@@ -389,7 +389,7 @@ class PgCMD(PgLock):
389
389
  if pgrqst: pgctl = self.get_dsrqst_control(pgrqst, logact)
390
390
  return pgctl
391
391
 
392
- def get_dynamic_options(self, cmd, oindex, otype):
392
+ def get_dynamic_options(self, cmd, oindex, otype, hostname=None):
393
393
  """Runs cmd to retrieve dynamic option strings, retrying on timeout.
394
394
 
395
395
  Executes the command up to three times, retrying when a connection
@@ -401,6 +401,11 @@ class PgCMD(PgLock):
401
401
  oindex (int or None): Object index appended to cmd when truthy.
402
402
  otype (str or None): Object type appended to cmd when truthy;
403
403
  'R' selects the first option from a slash-separated pair.
404
+ hostname (str or None): If provided, the command is executed
405
+ remotely via ``ssh <hostname> ...`` instead of locally; the
406
+ leading command name is resolved to its absolute path via
407
+ ``command_path`` so the remote shell does not depend on its
408
+ own PATH.
404
409
 
405
410
  Returns:
406
411
  str: The parsed option string, or '' if the command produced no
@@ -408,6 +413,7 @@ class PgCMD(PgLock):
408
413
  """
409
414
  if oindex: cmd += " {}".format(oindex)
410
415
  if otype: cmd += ' ' + otype
416
+ if hostname: cmd = "ssh {} {}".format(hostname, self.command_path(cmd))
411
417
  ret = options = ''
412
418
  for loop in range(3):
413
419
  ret = self.pgsystem(cmd, self.LOGWRN, 1299) # 1+2+16+256+1024
@@ -180,6 +180,7 @@ class PgLOG:
180
180
  self.BCHCMDS = {'PBS': 'qsub'}
181
181
  # global dists to cashe information
182
182
  self.COMMANDS = {}
183
+ self.CMDPATHS = {} # cache of bare command name -> full path (or '' if not found)
183
184
  self.PBSHOSTS = []
184
185
  self.PBSSTATS = {}
185
186
  # set additional common PGLOG values
@@ -1197,15 +1198,19 @@ class PgLOG:
1197
1198
  Returns:
1198
1199
  String with the leading command resolved to its full path, or the
1199
1200
  original *cmdstr* if the command already contains a path separator
1200
- or cannot be found via ``shutil.which``.
1201
+ or cannot be found via ``shutil.which``. Results of the
1202
+ ``shutil.which`` lookup are cached in ``self.CMDPATHS``.
1201
1203
  """
1202
1204
  if not cmdstr: return ''
1203
- ary = cmdstr.split(' ', 1)
1204
- cmd = ary[0]
1205
- if re.search(r'[\\/]', cmd): return cmdstr
1206
- optstr = (' ' + ary[1]) if len(ary) > 1 else ''
1207
- pcmd = shutil.which(cmd)
1208
- return (pcmd+optstr) if pcmd else cmdstr
1205
+ sp = cmdstr.find(' ')
1206
+ cmd = cmdstr if sp < 0 else cmdstr[:sp]
1207
+ if '/' in cmd or '\\' in cmd: return cmdstr
1208
+ pcmd = self.CMDPATHS.get(cmd)
1209
+ if pcmd is None:
1210
+ pcmd = shutil.which(cmd) or ''
1211
+ self.CMDPATHS[cmd] = pcmd
1212
+ if not pcmd: return cmdstr
1213
+ return pcmd if sp < 0 else pcmd + cmdstr[sp:]
1209
1214
 
1210
1215
  def add_carbon_copy(self, cc=None, isstr=None, exclude=0, specialist=None):
1211
1216
  """Update the Cc address list in ``PGLOG['CCDADDR']``.
@@ -64,23 +64,29 @@ class PgPassword(PgDBI):
64
64
  Parse ``sys.argv`` and apply CLI overrides.
65
65
 
66
66
  Recognized options:
67
- -l URL -- OpenBao URL (stored in self.PGDBI['BAOURL'])
68
- -k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN'])
69
- -d NAME -- PostgreSQL database name
70
- -c NAME -- PostgreSQL schema name
71
- -u NAME -- PostgreSQL login user name
72
- -h HOST -- PostgreSQL server host name
73
- -p PORT -- PostgreSQL port number
67
+ -? / --help -- show usage and exit
68
+ -l URL -- OpenBao URL (stored in self.PGDBI['BAOURL'])
69
+ -k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN'])
70
+ -d NAME -- PostgreSQL database name
71
+ -c NAME -- PostgreSQL schema name
72
+ -u NAME -- PostgreSQL login user name
73
+ -h HOST -- PostgreSQL server host name
74
+ -p PORT -- PostgreSQL port number
74
75
 
75
- If no arguments are supplied a usage message is printed and the
76
- process exits with status 0. Unknown options or stray values
77
- cause an immediate error exit via ``self.pglog(..., LGEREX)``.
76
+ With no arguments, all defaults inherited from PgDBI/PgLOG are
77
+ used and the password lookup proceeds. Unknown options, stray
78
+ values, or an option without its required value cause an
79
+ immediate error exit via ``self.pglog(..., LGEREX)``.
78
80
  """
79
81
  argv = sys.argv[1:]
80
82
  opt = None
81
- dohelp = True
82
83
  for arg in argv:
83
- if re.match(r'^-[a-zA-Z]$', arg):
84
+ if arg in ('-?', '-help', '--help'):
85
+ self.set_help_path(__file__)
86
+ self.show_usage("pgpassword")
87
+ elif re.match(r'^-[a-zA-Z]$', arg):
88
+ if opt:
89
+ self.pglog("-" + opt + ": missing option value", self.LGEREX)
84
90
  opt = arg[1:]
85
91
  elif opt:
86
92
  if opt == 'l':
@@ -91,13 +97,12 @@ class PgPassword(PgDBI):
91
97
  self.dbopt = True
92
98
  self.DBINFO[self.DBFLDS[opt]] = arg
93
99
  else:
94
- self.pglog(arg + ": Unknown option", self.LGEREX)
95
- dohelp = False
100
+ self.pglog("-" + opt + ": Unknown option", self.LGEREX)
101
+ opt = None
96
102
  else:
97
- self.pglog(arg + ": Value provided without option", self.LGEREX)
98
- if dohelp:
99
- self.set_help_path(__file__)
100
- self.show_usage("pgpassword")
103
+ self.pglog(arg + ": value provided without option", self.LGEREX)
104
+ if opt:
105
+ self.pglog("-" + opt + ": missing option value", self.LGEREX)
101
106
 
102
107
  # get the pgpassword
103
108
  def start_actions(self):
@@ -114,7 +119,7 @@ class PgPassword(PgDBI):
114
119
  self.password = self.get_baopassword()
115
120
  if not self.password: self.password = self.get_pgpassword()
116
121
 
117
- # main function to excecute this script
122
+ # main function to execute this script
118
123
  def main():
119
124
  """Entry point for the ``pgpassword`` console script: print the retrieved password to stdout."""
120
125
  object = PgPassword()
@@ -0,0 +1,57 @@
1
+
2
+ Retrieve a PostgreSQL login password for use by RDA python applications.
3
+ The password is looked up first from OpenBao (using the URL and token
4
+ configured in PgDBI) and, if not found there, from the user's .pgpass
5
+ file. The retrieved password is printed to stdout so that shell
6
+ wrappers and other RDA utilities can capture it.
7
+
8
+ Usage: pgpassword [-?] [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \
9
+ [-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]
10
+
11
+ With no options, pgpassword retrieves the password using all defaults
12
+ inherited from PgDBI/PgLOG (see per-option defaults below).
13
+
14
+ - Option -?, show this usage information and exit (also -help
15
+ and --help);
16
+
17
+ - Option -l, OpenBao URL used to retrieve passwords. Overrides
18
+ the BAOURL value from the PgDBI configuration.
19
+ Default: https://bao.k8s.ucar.edu/
20
+
21
+ - Option -k, OpenBao token name used to authenticate the password
22
+ lookup. Overrides the BAOTOKEN value from the PgDBI
23
+ configuration.
24
+
25
+ - Option -d, PostgreSQL database name.
26
+ Default: rdadb
27
+
28
+ - Option -c, PostgreSQL schema name.
29
+ Default: dssdb
30
+
31
+ - Option -u, PostgreSQL login user name.
32
+ Default: dssdb (same as the -c default)
33
+
34
+ - Option -h, PostgreSQL server host name.
35
+ Default: value of the DSSDBHOST environment variable, or
36
+ rda-db.ucar.edu if DSSDBHOST is not set.
37
+
38
+ - Option -p, PostgreSQL server port number.
39
+ Default: 5432
40
+
41
+ If any of -d, -c, -u, -h, or -p is supplied, the values are applied
42
+ via default_scinfo() before the password lookup is performed.
43
+
44
+ Examples:
45
+
46
+ 1. Retrieve the password for the default database/user configured
47
+ in PgDBI:
48
+
49
+ pgpassword
50
+
51
+ 2. Retrieve the password for a specific database, schema and user:
52
+
53
+ pgpassword -d rdadb -c dssdb -u metauser
54
+
55
+ 3. Retrieve the password from a custom OpenBao endpoint:
56
+
57
+ pgpassword -l https://bao.example.org -k my-token -d rdadb
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rda_python_common
3
- Version: 2.1.8
3
+ Version: 2.1.10
4
4
  Summary: RDA Python common library codes shared by other RDA python packages
5
5
  Author-email: Zaihua Ji <zji@ucar.edu>
6
6
  Project-URL: Homepage, https://github.com/NCAR/rda-python-common
@@ -92,7 +92,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN)
92
92
  python -c "import rda_python_common; print(rda_python_common.__version__)"
93
93
  ```
94
94
 
95
- You should see the installed version (currently `2.1.8`). If the import
95
+ You should see the installed version (currently `2.1.10`). If the import
96
96
  fails, double-check that the active Python environment is the one where you
97
97
  ran `pip install`.
98
98
 
@@ -22,6 +22,7 @@ src/rda_python_common/pg_sig.py
22
22
  src/rda_python_common/pg_split.py
23
23
  src/rda_python_common/pg_util.py
24
24
  src/rda_python_common/pgpassword.py
25
+ src/rda_python_common/pgpassword.usg
25
26
  src/rda_python_common.egg-info/PKG-INFO
26
27
  src/rda_python_common.egg-info/SOURCES.txt
27
28
  src/rda_python_common.egg-info/dependency_links.txt