Skip to content

Commit

Permalink
use local logger
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMarchand20 committed Jun 10, 2023
1 parent 99f88e4 commit eb5a913
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
20 changes: 11 additions & 9 deletions asciinema_automation/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import random
import time

logger = logging.getLogger(__name__)


class Instruction:
def run(self, script):
logging.info(self.__class__.__name__)
logger.info(self.__class__.__name__)


class ChangeWaitInstruction(Instruction):
Expand All @@ -15,7 +17,7 @@ def __init__(self, wait):

def run(self, script):
super().run(script)
logging.debug("%s->%s", script.wait, self.wait)
logger.debug("%s->%s", script.wait, self.wait)
script.wait = self.wait


Expand All @@ -26,7 +28,7 @@ def __init__(self, delay):

def run(self, script):
super().run(script)
logging.debug("%s->%s", script.delay, self.delay)
logger.debug("%s->%s", script.delay, self.delay)
script.delay = self.delay


Expand All @@ -38,7 +40,7 @@ def __init__(self, expect_value: str, timeout: int):

def run(self, script):
super().run(script)
logging.debug("Expect %s", repr(self.expect_value))
logger.debug("Expect %s", repr(self.expect_value))
script.process.expect(self.expect_value, timeout=self.timeout)


Expand All @@ -49,7 +51,7 @@ def __init__(self, send_value):

def run(self, script):
super().run(script)
logging.debug("Send %s", repr(self.send_value))
logger.debug("Send %s", repr(self.send_value))
self.receive_value = self.send_value

# Check for special character
Expand Down Expand Up @@ -84,7 +86,7 @@ def __init__(self, send_value):

def run(self, script):
super().run(script)
logging.debug("Send '%s'", self.send_value)
logger.debug("Send '%s'", self.send_value)
script.process.send(self.send_value)


Expand All @@ -94,7 +96,7 @@ def __init__(self, command):

def run(self, script):
super().run(script)
logging.debug("Send '\\n'")
logger.debug("Send '\\n'")
script.process.send("\n")


Expand All @@ -105,7 +107,7 @@ def __init__(self, control):

def run(self, script):
super().run(script)
logging.debug("Send ctrl+%s", self.control)
logger.debug("Send ctrl+%s", self.control)
script.process.sendcontrol(self.control)


Expand All @@ -128,7 +130,7 @@ def __init__(self, send, num, enter=False):

def run(self, script):
super().run(script)
logging.debug("Send %s arrow %i times", self.send, self.num)
logger.debug("Send %s arrow %i times", self.send, self.num)
for _ in range(self.num):
if script.standart_deviation is None:
time.sleep(script.delay)
Expand Down
22 changes: 12 additions & 10 deletions asciinema_automation/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
re.UNICODE | re.VERBOSE,
)

logger = logging.getLogger(__name__)


def decode_escapes(s):
def decode_match(match):
Expand Down Expand Up @@ -143,30 +145,30 @@ def execute(self):
spawn_command = (
"asciinema rec " + str(self.outputfile) + " " + self.asciinema_arguments
)
logging.info(spawn_command)
logger.info(spawn_command)
self.process = pexpect.spawn(spawn_command, logfile=None)

self.process.expect("\n")
logging.debug(self.process.before)
logger.debug(self.process.before)
if not (
"recording asciicast to " + str(self.outputfile) in str(self.process.before)
):
self.process.expect(pexpect.EOF)
self.process.close()
logging.debug("Exit status:" + str(self.process.exitstatus))
logging.debug("Signal status:" + str(self.process.signalstatus))
logger.debug("Exit status:" + str(self.process.exitstatus))
logger.debug("Signal status:" + str(self.process.signalstatus))
else:
self.process.expect("\n")
logging.debug(self.process.before)
logging.debug(self.process.after)
logging.info("Start reading instructions")
logger.debug(self.process.before)
logger.debug(self.process.after)
logger.info("Start reading instructions")
for instruction in self.instructions:
time.sleep(self.wait)
instruction.run(self)
time.sleep(self.wait)
logging.info("Finished reading instructions")
logger.info("Finished reading instructions")
self.process.sendcontrol("d")
self.process.expect(pexpect.EOF)
self.process.close()
logging.debug("Exit status:" + str(self.process.exitstatus))
logging.debug("Signal status:" + str(self.process.signalstatus))
logger.debug("Exit status:" + str(self.process.exitstatus))
logger.debug("Signal status:" + str(self.process.signalstatus))

0 comments on commit eb5a913

Please sign in to comment.