Beispiel #1
0
    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)
Beispiel #2
0
    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()
Beispiel #3
0
    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()
Beispiel #4
0
    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)
Beispiel #5
0
    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()
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
    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()
Beispiel #9
0
def select_files(options):
    options.top = os.path.abspath(options.top)
    #print("top",options.top)
    wildcard = WildCard(options.wildcard)
    filepaths = []

    if options.no_walk:
        # Select only the files in the top directory.
        fnames = [os.path.join(options.top, f) for f in os.listdir(options.top)]
        fnames = filter(os.path.isfile, fnames)
        #print(fnames)
        filepaths += wildcard.filter(fnames)

    else:
        # Navigate the directory tree starting from top.
        for root, dirnames, filenames in os.walk(options.top):
            fnames = [os.path.join(root, f) for f in filenames]
            filepaths += wildcard.filter(fnames)

    return filepaths
Beispiel #10
0
def select_files(options):
    options.top = os.path.abspath(options.top)
    #print("top",options.top)
    wildcard = WildCard(options.wildcard)
    filepaths = []

    if options.no_walk:
        # Select only the files in the top directory.
        fnames = [os.path.join(options.top, f) for f in os.listdir(options.top)]
        fnames = filter(os.path.isfile, fnames)
        #print(fnames)
        filepaths += wildcard.filter(fnames)

    else:
        # Navigate the directory tree starting from top.
        for root, dirnames, filenames in os.walk(options.top):
            fnames = [os.path.join(root, f) for f in filenames]
            filepaths += wildcard.filter(fnames)

    return filepaths