コード例 #1
0
ファイル: editor.py プロジェクト: fgoudreault/abipy
    def from_files_and_dir(cls,
                           parent,
                           filenames=None,
                           dirpath=None,
                           walk=True,
                           wildcard=""):
        """
        Static constructure that reads the content of the files/directory specified in input.

        Args:
            filenames:
                List of files to show in the botebook. Defaults to an empty list.
            dirpath:
                Directory to scan for additional files.
            walk:
                Used only if dirpath is not None.
                If True, we scan all the files contained within dirpath and 
                we add them to the list if their name match the regular expression 
                given in wildcard.
            wildcard:
                String with regular expressions separated by `|`.
                Only the files matching one of the regular expressions will be showed.
                example: wildcard='*.nc|*.txt' shows only the files whose extension is in ['nc', 'txt'].
        """
        wildcard = WildCard(wildcard)

        if filenames is None:
            filenames = []

        filenames = wildcard.filter(filenames)

        if dirpath is not None:
            if not walk:
                filenames += wildcard.filter(os.listdir(dirpath))

            else:
                for root, dirnames, fnames in os.walk(dirpath):
                    for fname in fnames:
                        if wildcard.match(fname):
                            filenames.append(os.path.join(root, fname))

        #frame = EditorNotebookFrame(parent)
        #frame.notebook.DeletePage(0)
        #for fname in filenames:
        #    frame.bufferCreate(filename=fname)
        #return frame

        # Open the files and read the content in a string
        text_list = []
        for fname in filenames:
            with open(fname, "r") as fh:
                # Sanitize strings: use "ignore" to skip invalid characters in .encode/.decode like
                s = fh.read().decode("utf-8", "ignore")
                text_list.append(s)

        return cls(parent, text_list, page_names=filenames)
コード例 #2
0
ファイル: editor.py プロジェクト: davidwaroquiers/abipy
    def from_files_and_dir(cls, parent, filenames=None, dirpath=None, walk=True, wildcard=""):
        """
        Static constructure that reads the content of the files/directory specified in input.

        Args:
            filenames:
                List of files to show in the botebook. Defaults to an empty list.
            dirpath:
                Directory to scan for additional files.
            walk:
                Used only if dirpath is not None.
                If True, we scan all the files contained within dirpath and 
                we add them to the list if their name match the regular expression 
                given in wildcard.
            wildcard:
                String with regular expressions separated by `|`.
                Only the files matching one of the regular expressions will be showed.
                example: wildcard='*.nc|*.txt' shows only the files whose extension is in ['nc', 'txt'].
        """
        wildcard = WildCard(wildcard)

        if filenames is None:
            filenames = []

        filenames = wildcard.filter(filenames)

        if dirpath is not None:
            if not walk:
                filenames += wildcard.filter(os.listdir(dirpath))

            else:
                for root, dirnames, fnames in os.walk(dirpath):
                    for fname in fnames:
                        if wildcard.match(fname):
                            filenames.append(os.path.join(root, fname))

        #frame = EditorNotebookFrame(parent)
        #frame.notebook.DeletePage(0)
        #for fname in filenames:
        #    frame.bufferCreate(filename=fname)
        #return frame

        # Open the files and read the content in a string
        text_list = []
        for fname in filenames:
            with open(fname, "r") as fh:
                # Sanitize strings: use "ignore" to skip invalid characters in .encode/.decode like
                s = fh.read().decode("utf-8", "ignore")
                text_list.append(s)

        return cls(parent, text_list, page_names=filenames)
コード例 #3
0
ファイル: browser.py プロジェクト: xue-smile/abipy
    def __init__(self,
                 parent,
                 dirpaths=None,
                 filepaths=None,
                 walk=True,
                 wildcard="",
                 **kwargs):
        """
        Args:
            parent:
                parent window
            dirpaths:
                List of directories to scan.
            filepaths
                List of filepaths (absolute paths).
            walk:
                True if we have to browse all files and directories starting from filepaths.
            wildcard
                Regular expressions for selecting files (tokens are separated by |).
        """
        super(FileListFrame, self).__init__(parent, -1, **kwargs)

        if dirpaths is not None:
            dirpaths = map(os.path.abspath, list_strings(dirpaths))
        else:
            dirpaths = []

        if filepaths is not None:
            filepaths = map(os.path.abspath, list_strings(filepaths))
        else:
            filepaths = []

        wildcard = WildCard(wildcard)

        self.all_filepaths = filepaths

        if walk:
            for dirpath in dirpaths:
                for root, dirnames, filenames in os.walk(dirpath):
                    fnames = [os.path.join(root, f) for f in filenames]
                    self.all_filepaths += wildcard.filter(fnames)
        else:
            # Select only the files in dirpaths.
            for dirpath in dirpaths:
                fnames = [os.path.join(dirpat, f) for f in os.listdir(dirpath)]
                fnames = filter(os.path.isfile, fnames)
                self.all_filepaths += wildcard.filter(fnames)

        self.BuildUi()
コード例 #4
0
ファイル: browser.py プロジェクト: gmatteo/abipy
    def __init__(self, parent, dirpaths=None, filepaths=None, walk=True, wildcard="", **kwargs):
        """
        Args:
            parent:
                parent window
            dirpaths:
                List of directories to scan.
            filepaths
                List of filepaths (absolute paths).
            walk:
                True if we have to browse all files and directories starting from filepaths.
            wildcard
                Regular expressions for selecting files (tokens are separated by |).
        """
        super(FileListFrame, self).__init__(parent, -1, **kwargs)

        if dirpaths is not None:
            dirpaths = map(os.path.abspath, list_strings(dirpaths))
        else:
            dirpaths = []

        if filepaths is not None:
            filepaths = map(os.path.abspath, list_strings(filepaths))
        else:
            filepaths = []

        wildcard = WildCard(wildcard)

        self.all_filepaths = filepaths

        if walk:
            for dirpath in dirpaths:
                for root, dirnames, filenames in os.walk(dirpath):
                    fnames = [os.path.join(root, f) for f in filenames]
                    self.all_filepaths += wildcard.filter(fnames)
        else:
            # Select only the files in dirpaths.
            for dirpath in dirpaths:
                fnames = [os.path.join(dirpat, f) for f in os.listdir(dirpath)]
                fnames = filter(os.path.isfile, fnames)
                self.all_filepaths += wildcard.filter(fnames)

        self.BuildUi()
コード例 #5
0
ファイル: browser.py プロジェクト: gmatteo/abipy
    def OnFilterComboBox(self, event):
        wildcard = WildCard(self.filter_combobox.GetValue())

        select_files = wildcard.filter(self.all_filepaths)
        panel = FileListPanel(self, filepaths=select_files)

        main_sizer = self.main_sizer
        main_sizer.Hide(0)
        main_sizer.Remove(0)
        main_sizer.Insert(0, panel, 1, wx.EXPAND, 5)

        self.Layout()
コード例 #6
0
ファイル: browser.py プロジェクト: xue-smile/abipy
    def OnFilterComboBox(self, event):
        wildcard = WildCard(self.filter_combobox.GetValue())

        select_files = wildcard.filter(self.all_filepaths)
        panel = FileListPanel(self, filepaths=select_files)

        main_sizer = self.main_sizer
        main_sizer.Hide(0)
        main_sizer.Remove(0)
        main_sizer.Insert(0, panel, 1, wx.EXPAND, 5)

        self.Layout()
コード例 #7
0
ファイル: extract_docs.py プロジェクト: temok-mx/abipy
def main():
    # Find (runnable) scripts.
    dir = os.path.dirname(os.path.abspath(__file__))
    wildcard = WildCard("run_*.py")
    scripts = [f.replace(".py", "") for f in wildcard.filter(os.listdir(dir))]

    retcode = 0

    for script in scripts:
        mod = __import__(script)
        if mod.__doc__ is None: retcode += 1
        doc = str(mod.__doc__).lstrip().rstrip()

        print(script + ":\n" + doc + "\n")

    #assert retcode == 0
    return retcode
コード例 #8
0
ファイル: make_readme.py プロジェクト: davidwaroquiers/abipy
def main():
    # Find (runnable) scripts.
    dir = os.path.dirname(os.path.abspath(__file__))
    wildcard = WildCard("run_*.py")
    scripts = [f.replace(".py", "") for f in wildcard.filter(os.listdir(dir))]

    missing = []
    with open("README.md", "wt") as fh:
        for script in scripts:
            mod = __import__(script)
            if mod.__doc__ is None: missing.append(script)
            doc = str(mod.__doc__).lstrip().rstrip()
            print("`%s`" % script + ":\n" + doc + "\n", file=fh)

    if missing:
        raise RuntimeError("The following script do not provide a doc string:\n" + "\n".join(missing))

    return len(missing)
コード例 #9
0
ファイル: _make_readme.py プロジェクト: fgoudreault/abipy
def main():
    # Find (runnable) scripts.
    dir = os.path.dirname(os.path.abspath(__file__))
    wildcard = WildCard("run_*.py")
    scripts = [f.replace(".py", "") for f in wildcard.filter(os.listdir(dir))]

    missing = []
    with open("README.md", "wt") as fh:
        for script in scripts:
            mod = __import__(script)
            if mod.__doc__ is None: missing.append(script)
            doc = str(mod.__doc__).lstrip().rstrip()
            print("`%s`" % script + ":\n" + doc + "\n", file=fh)

    if missing:
        raise RuntimeError(
            "The following script do not provide a doc string:\n" +
            "\n".join(missing))

    return len(missing)