Esempio n. 1
0
 def __init__(self, args):
     self.args = args
     self.topic = None
     self.steps = None
     self.last_step = 0
     self.guide_topics = None
     self.convert = False
     self.fake_run = False
     Log.info("Initializing...")
Esempio n. 2
0
    def output(cls):
        """Dump report of each saved property.
        """

        ran_status = (cls.current_step, cls.total_steps)
        Log.info("""Topic name: "%s" """ % cls.topic)
        Log.info("Steps ran successful %d out of %d" % ran_status)
        Log.info("""Last step error: "%s" """ % cls.error)
        Log.info("Runtime %ss" % cls.runtime)
        Log.info("Build %s" % cls.status.upper())
Esempio n. 3
0
def unlock():
    """Releases a lock file.

    Raises:
        OSError: If lock file cannot be released.
    """

    if os.path.isfile(LOCK_FILE):
        os.remove(LOCK_FILE)
        Log.info("Removed temporary lock")
Esempio n. 4
0
    def run(self, ignore_fails=False):
        """Run all steps for the current selected topic.
        """

        if self.fake_run:
            Log.info("Topic '%s' faked run" % self.topic.get_title())
            Report.set_status("FAKED")
        else:
            self.launch_topic(ignore_fails)

        if self.convert:
            self.launch_convertion()
Esempio n. 5
0
def lock():
    """Create a lock file.

    Raises:
        SystemExit: If a lock file already exists.
    """

    if os.path.isfile(LOCK_FILE):
        raise SystemExit("A build might be launched by another process")
    with open(LOCK_FILE, "a"):
        os.utime(LOCK_FILE, None)
        Log.info("Created temporary lock")
Esempio n. 6
0
    def setup(self):
        """Setup project path, topic and topic pattern, convertion type.
        """

        # Look for a specific topic
        if self.args.topic is not None:
            Topic.set_project_topic(self.args.topic)
            Log.info("Topic changed to: %s" % self.args.topic)

        # Set topic pattern
        if self.args.topic_pattern is not None:
            Topic.set_project_topic_pattern(self.args.topic_pattern)
            Log.info("Topic pattern changed to: %s" % self.args.topic_pattern)

        # Change project path from current working directory to choosen path
        if self.args.guide is not None:
            Reader.set_project_path(self.args.guide)
            Log.info("Project guide location: %s" % self.args.guide)

        # Convert build steps to script before exit
        if self.args.convert is not None:
            Converter.prepare(self.args.convert)
            Log.info("Topic convertion set to: %s" % self.args.convert)
            self.convert = True

        # Toggle fake run
        self.fake_run = self.args.fake_run
Esempio n. 7
0
    def print_report(self):
        """Dumps a report of the script outcome.
        """

        Log.info("Preparing to print report...")
        Report.output()
Esempio n. 8
0
    def parse(self):
        """Parse guide and extract topics.

        User prompter asks to choose a topic from the selection in order to
        know what steps are queued.
        """

        rr = ReadmeReader(validate=True)
        rr.read()
        rr.parse()
        Log.info("Parsing guide...")

        # Preview scanned guide
        if self.args.preview:
            Log.info("Loading guide preview...")
            rr.preview(150)

        # Scan guide for topics
        if self.args.topic is None:
            guide = rr.get_guide()
        else:
            guide = rr.get_guide_by_topic()
        if guide is None:
            Log.fatal("Guide has no such topic")

        # Prepare guide topics
        self.guide_topics = guide.get_topics()

        # Pair each step with appropriate statement
        if self.args.strict:
            if not all([self.pair_steps(t) for t in self.guide_topics]):
                Report.set_status("Halted")
                Report.set_error("Unsupported steps")
                Log.fatal("Cannot continue because of unsupported steps")
        else:
            for t in self.guide_topics:
                for step in t.get_steps():
                    pair = Matcher.pair_one(step)
                    if not pair:
                        self.guide_topics.remove(t)

        # Scan topics
        topics = [t.get_title() for t in guide.get_topics()]
        topics_len = len(topics)

        # Handle no topics
        if topics_len == 0:
            Log.fatal("No topics found")
        else:
            Log.info("Guide has %d topics" % topics_len)

        # Handle topics
        Log.info("Found the following topics...")
        print("")
        for pos, name in enumerate(topics):
            print(("%" + str(len(str(topics_len)) + 5) + "d) %s") %
                  (pos + 1, name))
        print(RUN_INSTRUCTIONS)

        # Display warnings
        if self.args.unsafe_shell:
            print(WARNING_UNSAFE_SHELL)

        # Save topic and topic's steps
        self.topic = self.get_user_input()
        self.steps = self.topic.get_steps()

        # Confirm topic
        print("")
        Log.info(u"Matching topic \033[92m%s\033[0m" % self.topic.get_title())

        # Patch topic imports
        self.patch_topic_invoke(self.steps)

        # Prepare report
        Report.set_total_steps(len(self.steps))
        Report.set_topic(self.topic.get_title())
        return self
Esempio n. 9
0
    def launch_topic(self, ignore_fails=False, failed=False):
        """Launch topic and run all steps.
        """

        total_steps = len(self.topic.get_steps())
        Log.info("Preparing to run %d steps from topic..." % total_steps)

        # Loop steps and run each one
        start_time = default_timer()
        Log.debug("Setting start time: %s" % start_time)

        success_log = u"\033[92m\u2713 (Success)\033[0m \033[93m%s\033[0m"
        failed_log = u"\033[91m? (Failed)\033[0m \033[95m%s\033[0m"
        error_log = u"\033[91m? (Error) %s\033[0m"

        for self.last_step, step in enumerate(self.steps):
            step_count, step_desc = self.last_step + 1, step.get_description()
            Log.debug("Preparing step (%d) %s" % (step_count, step_desc))
            Log.info(u"Running \033[93m%s\033[0m ..." % step.get_step())
            try:
                success, output = step.run()
                if success:
                    Log.info(success_log % output)
                else:
                    Log.info(failed_log % output)
                    if not ignore_fails:
                        failed = True
                        Report.set_error(output)
                        break
                Report.inc_step(1)
            except KeyboardInterrupt:
                Log.info("Stopping current step...")
                Log.warn("Interrupting may lead to unexpected results")
                Log.warn("Stop master process at your own risk (PID %s)" % PID)
            except Exception as e:
                failed = True
                Report.set_error(e)
                Log.info(error_log % str(e))
                break

        stop_time = default_timer()
        Log.debug("Set stop time: %s" % stop_time)
        Log.debug("Runtime %ss" % (stop_time - start_time))

        # Save runtime
        Report.set_runtime(stop_time - start_time)

        # Wrap up...
        Log.debug("Done running steps...")
        title = self.topic.get_title()
        if failed:
            Log.info("An error occured while topic '%s' was running" % title)
            Report.set_status("Failed")
        else:
            Log.info("Topic '%s' has ran all steps with no errors" % title)
            Report.set_status("OK")
        Log.debug("Closing...")