Exemplo n.º 1
0
    def ls(self, add_files=True, add_dirs=True, add_details=False):

        files = []

        try:

            res = self.eval("os.listdir('%s')" % self.dir)
            tmp = ast.literal_eval(res.decode('utf-8'))

            if add_dirs:
                for f in tmp:
                    try:

                        # if it is a dir, it could be listed with "os.listdir"
                        self.eval("os.listdir('%s/%s')" %
                                  (self.dir.rstrip('/'), f))
                        if add_details:
                            files.append((f, 'D'))
                        else:
                            files.append(f)

                    except PyboardError as e:

                        if _was_file_not_existing(e):
                            # this was not a dir
                            if self.sysname == "WiPy" and self.dir == "/":
                                # for the WiPy, assume that all entries in the root of th FS
                                # are mount-points, and thus treat them as directories
                                if add_details:
                                    files.append((f, 'D'))
                                else:
                                    files.append(f)
                        else:
                            raise e

            if add_files and not (self.sysname == "WiPy" and self.dir == "/"):
                for f in tmp:
                    try:

                        # if it is a file, "os.listdir" must fail
                        self.eval("os.listdir('%s/%s')" %
                                  (self.dir.rstrip('/'), f))

                    except PyboardError as e:

                        if _was_file_not_existing(e):
                            if add_details:
                                files.append((f, 'F'))
                            else:
                                files.append(f)
                        else:
                            raise e

        except Exception as e:
            if _was_file_not_existing(e):
                raise RemoteIOError("No such directory: %s" % self.dir)
            else:
                raise PyboardError(e)

        return files
Exemplo n.º 2
0
    def ls(self, add_files=True, add_dirs=True, add_details=False):

        files = []

        try:
            res = self.eval("list(uos.ilistdir('%s'))" % self.dir)
        except Exception as e:
            if _was_file_not_existing(e):
                raise RemoteIOError("No such directory: %s" % self.dir)
            else:
                raise PyboardError(e)

        entries = ast.literal_eval(res.decode("utf-8"))

        if self.sysname == "WiPy" and self.dir == "/":
            # Assume everything in the root is a mountpoint and return them as dirs.
            if add_details:
                return [(entry[0], "D") for entry in entries]
            else:
                return [entry[0] for entry in entries]

        for entry in entries:
            fname, ftype, inode = entry[:3]
            fchar = "D" if ftype == 0x4000 else "F"
            if not ((fchar == "D" and add_dirs) or
                    (fchar == "F" and add_files)):
                continue

            files.append((fname, fchar) if add_details else fname)

        if add_details:
            # Sort directories first, then filenames.
            return sorted(files, key=lambda x: (x[1], x[0]))
        else:
            return sorted(files)
Exemplo n.º 3
0
 def create_antkontrol(self):
     """Create an antkontrol object on the ESP32."""
     try:
         ret = self.exec_("import antenny")
         ret = self.exec_("a = antenny.AntKontrol()")
         self.antenna_initialized = True
         return ret.decode()
     except PyboardError:
         raise PyboardError("Could not create antkontrol object")