示例#1
0
    def check_instruction(self, line):
        """Check line from build steps if it's an instruction.

        Args:
            line (str): Build step line as string.

        Raises:
            Exception: If last topic is missing and step is found.

        Returns:
            self: Self instance.
        """

        if self.no_topic_skip and self.last_topic is None:
            self.last_step = None
            return self
        scan = Instruction.PATTERN.match(line)
        if scan is not None:
            step = scan.group("step")
            if Placeholder.scan_string(step):
                step = Placeholder.parse_string(step)
            punct = scan.group("punct")
            self.last_step = Instruction(self.get_line_number(), step, punct)
            if self.last_topic is None:
                Log.fatal("Unaccepted instruction: missing topic in guide")
            self.last_topic.add_step(self.last_step)
        return self
示例#2
0
文件: reader.py 项目: lexndru/buildok
    def set_project_path(cls, project_path):
        """Change project path.

        Default is current working directory.

        Args:
            project_path (str): New project path.

        Raises:
            ValueError: If project path is not a string.
        """

        if not isinstance(project_path, (str, unicode)):
            Log.fatal("Project path must be string")
        cls.PATH = project_path.rstrip("/")
示例#3
0
def crash(message):
    """Crash application with message.

    Raises:
        SystemExit.
    """

    return Log.fatal("Unexpected crash! %s" % message)
示例#4
0
文件: reader.py 项目: lexndru/buildok
    def setup(self):
        """Setup if reader is properly called.

        Raises:
            ValueError: Project does not have build file.

        Returns:
            bool: Returns True if project setup is done.
        """

        if self.READER is None or self.PATH is None:
            return False
        filepath = self.PATH
        if path.isdir(filepath):
            filepath = path.join(self.PATH, self.READER)
        self.filename = path.abspath(filepath)
        if not self.exists():
            Log.fatal("Project doesn't have proper build file: %s" % filepath)
        return True
示例#5
0
文件: script.py 项目: lexndru/buildok
    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