Skip to content

Commit

Permalink
fix toml
Browse files Browse the repository at this point in the history
  • Loading branch information
laszewsk committed Dec 27, 2023
1 parent 2f7386a commit c81a1de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ Changelog = "https://github.com/cloudmesh/cloudmesh-common/blob/main/CHANGELOG.m

[tool.setuptools.packages.find]
where = ["src"]
include = ["cloudmesh.common"]
include = ["cloudmesh.common", "cloudmesh.common.*"]
40 changes: 23 additions & 17 deletions src/cloudmesh/common/ssh/ssh_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


# noinspection PyPep8Naming
class ssh_config(object):
class ssh_config:
"""Managing the config in .ssh"""

def __init__(self, filename=None):
Expand Down Expand Up @@ -39,7 +39,7 @@ def names(self):
attribute, value = line.split(" ", 1)
attribute = attribute.strip()
value = value.strip()
if attribute.lower() in ['host']:
if attribute.lower() in ["host"]:
found_names.append(value)
return found_names

Expand All @@ -51,20 +51,22 @@ def load(self):
return self.hosts
with open(self.filename) as f:
content = f.readlines()
content = [" ".join(x.split()).strip('\n').lstrip().split(' ', 1) for x in content]
content = [
" ".join(x.split()).strip("\n").lstrip().split(" ", 1) for x in content
]

# removes duplicated spaces, and splits in two fields, removes leading spaces
hosts = {}
host = "NA"
for line in content:
if line[0].startswith('#') or line[0] == '':
if line[0].startswith("#") or line[0] == "":
pass # ignore line
else:
attribute = line[0]
value = line[1]
if attribute.lower().strip() in ['Host', 'host']:
if attribute.lower().strip() in ["Host", "host"]:
host = value
hosts[host] = {'host': host}
hosts[host] = {"host": host}
else:
# In case of special configuration lines, such as port
# forwarding,
Expand Down Expand Up @@ -119,9 +121,9 @@ def execute(self, name, command):
"""
if name in ["localhost"]:
r = '\n'.join(Shell.sh("-c", command).split()[-1:])
r = "\n".join(Shell.sh("-c", command).split()[-1:])
else:
r = '\n'.join(Shell.ssh(name, command).split()[-1:])
r = "\n".join(Shell.ssh(name, command).split()[-1:])
return r

def local(self, command):
Expand Down Expand Up @@ -166,13 +168,15 @@ def delete(name):

writefile(filename, result)

def generate(self,
host="india",
hostname="india.futuresystems.org",
identity="~/.ssh/id_rsa.pub",
user=None,
force=False,
verbose=False):
def generate(
self,
host="india",
hostname="india.futuresystems.org",
identity="~/.ssh/id_rsa.pub",
user=None,
force=False,
verbose=False,
):
"""adds a host to the config file with given parameters. #TODO: make sure this is better documented
Args:
Expand All @@ -190,12 +194,14 @@ def generate(self,
Console.error(f"{host} already in ~/.ssh/config", traceflag=False)
return ""
else:
entry = dedent(f"""
entry = dedent(
f"""
Host {host}
Hostname {hostname}
User {user}
IdentityFile {identity}
""")
"""
)
try:
with open(self.filename, "a") as config_ssh:
config_ssh.write(entry)
Expand Down

0 comments on commit c81a1de

Please sign in to comment.