コード例 #1
0
ファイル: __init__.py プロジェクト: wenzhang106/configuration
    def _ensure_revs(self, revs):
        i = 0
        length = len(revs)
        while i < length:
            (rev, handle) = revs[i]
            if rev is None:
                # now we must read the revision from the module
                try:
                    r = self.repository.get_module_from_handle(handle)
                except self.repository.ReadError, ex:
                    i += 1
                    continue
                (ref, format, text) = r

                if format == None:
                    format = util.guess_format(text)

                if format == 'yin':
                    p = yin_parser.YinParser({
                        'no_include': True,
                        'no_extensions': True
                    })
                else:
                    p = yang_parser.YangParser()

                module = p.parse(self, ref, text)
                if module is not None:
                    rev = util.get_latest_revision(module)
                    revs[i] = (rev, ('parsed', module, ref))
            i += 1
コード例 #2
0
ファイル: __init__.py プロジェクト: prashg28/pyang-ct
    def _ensure_revs(self, revs):
        i = 0
        length = len(revs)
        while i < length:
            (rev, handle) = revs[i]
            if rev is None:
                # now we must read the revision from the module
                try:
                    r = self.repository.get_module_from_handle(handle)
                except self.repository.ReadError, ex:
                    continue
                (ref, format, text) = r

                if format == None:
                    format = util.guess_format(text)
                    
                if format == 'yin':
                    p = yin_parser.YinParser({'no_include':True})
                else:
                    p = yang_parser.YangParser()

                module = p.parse(self, ref, text)
                if module is not None:
                    rev = util.get_latest_revision(module)
                    revs[i] = (rev, ('parsed', module, ref))
            i += 1
コード例 #3
0
ファイル: alvin.py プロジェクト: gearoidfox/alvin
def main():
    """
    Handle command line arguments and launch curses display, then enter
    curses_main()
    """

    epilog = """
    Reads MSAs in any format supported by BioPython. Autodetects alignments in
    FASTA, Stockholm, Phylip and Nexus formats.

    Current does not autodetect PIR format correctly.

    By default, all gaps are displayed as '.'

    To preserve the original gap symbols from the alignment file, use the
    --gapsym option.
    """

    description = """
    Terminal-based multiple sequence alignment viewer.
    """

    parser = argparse.ArgumentParser(epilog=epilog, description=description)
    parser.add_argument('aln_file', help="Path to alignment file.")
    parser.add_argument('--format', '-f', help="MSA format (skip autodetection)")
    parser.add_argument('--gapsym', help="Preserve gap symbols from file.",
            action='store_true', default=False)
    parser.add_argument('--nucleotide', '-n', action='store_true',
            default=False, help="Nucleotide alignment.")
    args = parser.parse_args()

    if args.format is None:
        args.format = guess_format(args.aln_file)
        if args.format is None:
            die( "FATAL: can't determine format of %s. Try specifying the "
                    "alignment format manually.\n" % args.aln_file, None)
    try:
        stdscr=curses.initscr()
        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        if curses.has_colors():
            curses.start_color()
        curses_main(stdscr, args)
    # don't print a stack trace if killed by, e.g, SIGINT
    # we just want to clean up the environment and quit
    except KilledException: 
        pass 
    finally:
        stdscr.erase()
        stdscr.refresh()
        stdscr.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
    return 0
コード例 #4
0
ファイル: __init__.py プロジェクト: prashg28/pyang-ct
    def read_module(self, modulename, revision=None, extra={}):
        """Searches for a module named `modulename` in the repository

        The module is just read, and not compiled at all.
        Returns the module if found, and None otherwise"""

        if modulename not in self.revs:
            # this module doesn't exist in the repos at all
            return None
        elif self.revs[modulename] == []:
            # this module doesn't exist in the repos at all, error reported
            return None

        if revision is not None:
            if (modulename,revision) in self.modules:
                return self.modules[(modulename, revision)]
            self._ensure_revs(self.revs[modulename])
            x = util.keysearch(revision, 1, self.revs[modulename])
            if x is not None:
                (_revision, handle) = x
                if handle == None:
                    # this revision doesn't exist in the repos, error reported
                    return None
            else:
                # this revision doesn't exist in the repos
                return None
        else:
            # get the latest revision
            (revision, handle) = self._get_latest_rev(self.revs[modulename])
            if (modulename, revision) in self.modules:
                return self.modules[(modulename, revision)]
            
        if handle[0] == 'parsed':
            module = handle[1]
            return module
        else:
            # get it from the repos
            try:
                r = self.repository.get_module_from_handle(handle)
                (ref, format, text) = r
                if format == None:
                    format = util.guess_format(text)

                if format == 'yin':
                    p = yin_parser.YinParser(extra)
                else:
                    p = yang_parser.YangParser(extra)

                return p.parse(self, ref, text)
            except self.repository.ReadError, ex:
                return None
コード例 #5
0
ファイル: __init__.py プロジェクト: wenzhang106/configuration
    def read_module(self, modulename, revision=None, extra={}):
        """Searches for a module named `modulename` in the repository

        The module is just read, and not compiled at all.
        Returns the module if found, and None otherwise"""

        if modulename not in self.revs:
            # this module doesn't exist in the repos at all
            return None
        elif self.revs[modulename] == []:
            # this module doesn't exist in the repos at all, error reported
            return None

        if revision is not None:
            if (modulename, revision) in self.modules:
                return self.modules[(modulename, revision)]
            self._ensure_revs(self.revs[modulename])
            x = util.keysearch(revision, 1, self.revs[modulename])
            if x is not None:
                (_revision, handle) = x
                if handle == None:
                    # this revision doesn't exist in the repos, error reported
                    return None
            else:
                # this revision doesn't exist in the repos
                return None
        else:
            # get the latest revision
            (revision, handle) = self._get_latest_rev(self.revs[modulename])
            if (modulename, revision) in self.modules:
                return self.modules[(modulename, revision)]

        if handle[0] == 'parsed':
            module = handle[1]
            return module
        else:
            # get it from the repos
            try:
                r = self.repository.get_module_from_handle(handle)
                (ref, format, text) = r
                if format == None:
                    format = util.guess_format(text)

                if format == 'yin':
                    p = yin_parser.YinParser(extra)
                else:
                    p = yang_parser.YangParser(extra)

                return p.parse(self, ref, text)
            except self.repository.ReadError, ex:
                return None
コード例 #6
0
ファイル: __init__.py プロジェクト: wenzhang106/configuration
    def add_module(self,
                   ref,
                   text,
                   format=None,
                   expect_modulename=None,
                   expect_revision=None,
                   expect_failure_error=True):
        """Parse a module text and add the module data to the context

        `ref` is a string which is used to identify the source of
              the text for the user.  used in error messages
        `text` is the raw text data
        `format` is one of 'yang' or 'yin'.

        Returns the parsed and validated module on success, and None on error.
        """
        if format == None:
            format = util.guess_format(text)

        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()

        module = p.parse(self, ref, text)
        if module is None:
            return None

        if expect_modulename is not None and expect_modulename != module.arg:
            if expect_failure_error:
                error.err_add(self.errors, module.pos, 'BAD_MODULE_NAME',
                              (module.arg, ref, expect_modulename))
                return None
            else:
                error.err_add(self.errors, module.pos, 'WBAD_MODULE_NAME',
                              (module.arg, ref, expect_modulename))
        if expect_revision is not None:
            latest_rev = util.get_latest_revision(module)
            if expect_revision != latest_rev:
                if expect_failure_error:
                    error.err_add(self.errors, module.pos, 'BAD_REVISION',
                                  (latest_rev, ref, expect_revision))
                    return None
                else:
                    error.err_add(self.errors, module.pos, 'WBAD_REVISION',
                                  (latest_rev, ref, expect_revision))

        module.i_adler32 = zlib.adler32(text)
        return self.add_parsed_module(module)
コード例 #7
0
    def add_module(self, ref, text, format=None,
                   expect_modulename=None, expect_revision=None,
                   expect_failure_error=True):
        """Parse a module text and add the module data to the context

        `ref` is a string which is used to identify the source of
              the text for the user.  used in error messages
        `text` is the raw text data
        `format` is one of 'yang' or 'yin'.

        Returns the parsed and validated module on success, and None on error.
        """
        if format == None:
            format = util.guess_format(text)

        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()

        module = p.parse(self, ref, text)
        if module is None:
            return None

        if expect_modulename is not None and expect_modulename != module.arg:
            if expect_failure_error:
                error.err_add(self.errors, module.pos, 'BAD_MODULE_NAME',
                              (module.arg, ref, expect_modulename))
                return None
            else:
                error.err_add(self.errors, module.pos, 'WBAD_MODULE_NAME',
                              (module.arg, ref, expect_modulename))
        if expect_revision is not None:
            latest_rev = util.get_latest_revision(module)
            if expect_revision != latest_rev:
                if expect_failure_error:
                    error.err_add(self.errors, module.pos, 'BAD_REVISION',
                                  (latest_rev, ref, expect_revision))
                    return None
                else:
                    error.err_add(self.errors, module.pos, 'WBAD_REVISION',
                                  (latest_rev, ref, expect_revision))

        module.i_adler32 = zlib.adler32(text)
        return self.add_parsed_module(module)
コード例 #8
0
ファイル: __init__.py プロジェクト: prashg28/pyang-ct
    def add_module(self, ref, text, format=None):
        """Parse a module text and add the module data to the context

        `ref` is a string which is used to identify the source of
              the text for the user.  used in error messages
        `text` is the raw text data
        `format` is one of 'yang' or 'yin'.

        Returns the parsed and validated module on success, and None on error.
        """
        if format == None:
            format = util.guess_format(text)

        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()

        module = p.parse(self, ref, text)
        if module is None:
            return None
        
        module.i_adler32 = zlib.adler32(text)
        return self.add_parsed_module(module)
コード例 #9
0
    def add_module(self, ref, text, format=None):
        """Parse a module text and add the module data to the context

        `ref` is a string which is used to identify the source of
              the text for the user.  used in error messages
        `text` is the raw text data
        `format` is one of 'yang' or 'yin'.

        Returns the parsed and validated module on success, and None on error.
        """
        if format == None:
            format = util.guess_format(text)

        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()

        module = p.parse(self, ref, text)
        if module is None:
            return None

        module.i_adler32 = zlib.adler32(text)
        return self.add_parsed_module(module)
コード例 #10
0
ファイル: __init__.py プロジェクト: prashg28/pyang-ct
        except IOError, ex:
            return None
        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()
        
        # FIXME: optimization - do not parse the entire text
        # just to read the revisiosn...
        module = p.parse(ctx, absfilename, text)
        if module is None:
            return None
        return (util.get_latest_revision(module), module)

    def get_modules_and_revisions(self, ctx):
        if self.modules is None:
            self._setup(ctx)
        return self.modules

    def get_module_from_handle(self, handle):
        (format, absfilename) = handle
        try:
            fd = file(absfilename)
            text = fd.read()
        except IOError, ex:
            raise self.ReadError(absfilename + ": " + str(ex))

        if format is None:
            format = util.guess_format(text)
        return (absfilename, format, text)
コード例 #11
0
ファイル: __init__.py プロジェクト: wenzhang106/configuration
        except IOError, ex:
            return None
        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()

        # FIXME: optimization - do not parse the entire text
        # just to read the revisions...
        module = p.parse(ctx, absfilename, text)
        if module is None:
            return None
        return (util.get_latest_revision(module), module)

    def get_modules_and_revisions(self, ctx):
        if self.modules is None:
            self._setup(ctx)
        return self.modules

    def get_module_from_handle(self, handle):
        (format, absfilename) = handle
        try:
            fd = file(absfilename)
            text = fd.read()
        except IOError, ex:
            raise self.ReadError(absfilename + ": " + str(ex))

        if format is None:
            format = util.guess_format(text)
        return (absfilename, format, text)