| 1 | # __init__.py - High-level automation interfaces |
| 2 | # |
| 3 | # Copyright 2019 Gregory Szorc <[email protected]> |
| 4 | # |
| 5 | # This software may be used and distributed according to the terms of the |
| 6 | # GNU General Public License version 2 or any later version. |
| 7 | |
| 8 | # no-check-code because Python 3 native. |
| 9 | |
| 10 | import pathlibscip-python python python-stdlib 3.11 pathlib/__init__: |
| 11 | import secretsscip-python python python-stdlib 3.11 secrets/__init__: |
| 12 | |
| 13 | from .awsscip-python python mercurial 7.2.2 aws/__init__: import AWSConnectionscip-python python mercurial 7.2.2 `contrib.automation.hgautomation.aws`/AWSConnection# |
| 14 | |
| 15 | |
| 16 | class HGAutomationscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#: |
| 17 | """High-level interface for Mercurial automation. |
| 18 | |
| 19 | Holds global state, provides access to other primitives, etc. |
| 20 | """ |
| 21 | |
| 22 | def __init__scip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#__init__().(selfscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#__init__().(self), state_pathscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#__init__().(state_path): pathlibscip-python python python-stdlib 3.11 pathlib/__init__:.Pathscip-python python python-stdlib 3.11 pathlib/Path#): |
| 23 | selfscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#__init__().(self).state_pathscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#state_path. = state_pathscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#__init__().(state_path) |
| 24 | |
| 25 | state_pathscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#__init__().(state_path).mkdirscip-python python python-stdlib 3.11 pathlib/Path#mkdir().(exist_okscip-python python python-stdlib 3.11 pathlib/Path#mkdir().(exist_ok)=True) |
| 26 | |
| 27 | def default_passwordscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#default_password().(selfscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#default_password().(self)): |
| 28 | """Obtain the default password to use for remote machines. |
| 29 | |
| 30 | A new password will be generated if one is not stored. |
| 31 | """ |
| 32 | p = selfscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#default_password().(self).state_pathscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#state_path. / 'default-password' |
| 33 | |
| 34 | try: |
| 35 | with p.openscip-python python python-stdlib 3.11 pathlib/Path#open().('r', encodingscip-python python python-stdlib 3.11 pathlib/Path#open().(encoding)='ascii') as fh: |
| 36 | data = fh.readscip-python python python-stdlib 3.11 io/TextIOBase#read().().stripscip-python python python-stdlib 3.11 builtins/str#strip().() |
| 37 | |
| 38 | if data: |
| 39 | return data |
| 40 | |
| 41 | except FileNotFoundErrorscip-python python python-stdlib 3.11 builtins/FileNotFoundError#: |
| 42 | pass |
| 43 | |
| 44 | password = secretsscip-python python python-stdlib 3.11 secrets/__init__:.token_urlsafescip-python python python-stdlib 3.11 secrets/token_urlsafe().(24) |
| 45 | |
| 46 | with p.openscip-python python python-stdlib 3.11 pathlib/Path#open().('w', encodingscip-python python python-stdlib 3.11 pathlib/Path#open().(encoding)='ascii') as fh: |
| 47 | fh.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(password) |
| 48 | fh.writescip-python python python-stdlib 3.11 io/TextIOBase#write().('\n') |
| 49 | |
| 50 | p.chmodscip-python python python-stdlib 3.11 pathlib/Path#chmod().(0o0600) |
| 51 | |
| 52 | return password |
| 53 | |
| 54 | def aws_connectionscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(selfscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(self), regionscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(region): strscip-python python python-stdlib 3.11 builtins/str#, ensure_ec2_statescip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(ensure_ec2_state): boolscip-python python python-stdlib 3.11 builtins/bool# = True): |
| 55 | """Obtain an AWSConnection instance bound to a specific region.""" |
| 56 | |
| 57 | return AWSConnectionscip-python python mercurial 7.2.2 `contrib.automation.hgautomation.aws`/AWSConnection#(selfscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(self), regionscip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(region), ensure_ec2_statescip-python python mercurial 7.2.2 `contrib.automation.hgautomation.aws`/AWSConnection#__init__().(ensure_ec2_state)=ensure_ec2_statescip-python python mercurial 7.2.2 `contrib.automation.hgautomation`/HGAutomation#aws_connection().(ensure_ec2_state)) |