Skip to content

Commit

Permalink
More code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
nrathaus committed Apr 9, 2023
1 parent 780bc22 commit 0676874
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions pbapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def set_phonebook(self, name="", to_root=False, to_parent=False):
if not isinstance(response, tuple) and isinstance(
response, responses.FailureResponse
):
logger.error("set_phonebook failed. reason = %s", name, response)
err = f"set_phonebook failed. reason = {response}"
logger.error(err)
return

if to_root:
Expand All @@ -169,9 +170,7 @@ class REPL(cmd2.Cmd):

def __init__(self):
cmd2.Cmd.__init__(self)
# self.prompt = self.colorize("pbap> ", "yellow")
self.prompt = cmd2.ansi.style("pbap> ", fg=cmd2.ansi.Fg.YELLOW)
# self.intro = self.colorize("Welcome to the PhoneBook Access Profile!", "green")
self.intro = cmd2.ansi.style(
"Welcome to the PhoneBook Access Profile!", fg=cmd2.ansi.Fg.GREEN
)
Expand Down Expand Up @@ -217,7 +216,6 @@ def do_connect(self, opts):
logger.error("Connect Failed, Terminating the Pbap client..")
sys.exit(2)
logger.info("Connect success")
# self.prompt = self.colorize("pbap> ", "green")
self.prompt = cmd2.ansi.style("pbap> ", fg=cmd2.ansi.Fg.GREEN)

def do_disconnect(self):
Expand All @@ -230,7 +228,6 @@ def do_disconnect(self):
logger.debug("Disconnecting pbap client with pbap server")
self.client.disconnect()
self.client = None
# self.prompt = self.colorize("pbap> ", "yellow")
self.prompt = cmd2.ansi.style("pbap> ", fg=cmd2.ansi.Fg.YELLOW)

# pull_phonebook_parser
Expand Down Expand Up @@ -403,11 +400,7 @@ def do_mirror_vfolder(self, opts):
current_dir = os.path.join(telecom_dir, pbobject)
os.makedirs(current_dir)
# Access the list of vcards in the phone's internal phone book.
response = self.client.pull_vcard_listing(
"{prefix}telecom/{pbobject}".format(
prefix=prefix, pbobject=pbobject
)
)
response = self.client.pull_vcard_listing(f"{prefix}telecom/{pbobject}")
if response is None:
logger.error(
"vcard-listing get is failed for pbobject '%s'", pbobject
Expand All @@ -427,11 +420,7 @@ def do_mirror_vfolder(self, opts):

logger.info("\nCards in %stelecom/%s\n", prefix, pbobject)
# Request all the file names obtained earlier.
self.client.set_phonebook(
"{prefix}telecom/{pbobject}".format(
prefix=prefix, pbobject=pbobject
)
)
self.client.set_phonebook(f"{prefix}telecom/{pbobject}")
for name in names:
response = self.client.pull_vcard_entry(name)
if response is None:
Expand Down Expand Up @@ -459,11 +448,7 @@ def do_mirror_vfolder(self, opts):
logger.info(
"\nThe phonebook in %s/telecom/%s as one vcard\n", prefix, pbobject
)
response = self.client.pull_phonebook(
"{prefix}telecom/{pbobject}.vcf".format(
prefix=prefix, pbobject=pbobject
)
)
response = self.client.pull_phonebook(f"{prefix}telecom/{pbobject}.vcf")
if response is None:
logger.error("phonebook get is failed for pbobject '%s'", pbobject)
continue
Expand All @@ -473,8 +458,8 @@ def do_mirror_vfolder(self, opts):
os.path.join(current_dir, prefix, "telecom", pbobject + ".vcf"),
"w+",
encoding="latin1",
) as f:
f.write(phonebook)
) as file_handle:
file_handle.write(phonebook)
logger.info(hdrs)

self.do_disconnect()
Expand Down

0 comments on commit 0676874

Please sign in to comment.