def list_files(self, remote_path='A/DCIM', detailed=False): """ Get directory listing for a path on the device. :param remote_path: Path on the device :type remote_path: str/unicode :param detailed: Return detailed information about each file/dir :type detailed: bool :return: All files and directories in the path """ remote_path = util.to_camerapath(remote_path) flist = self._lua.call("con:listdir", remote_path, dirsonly=False, stat="*" if detailed else "/") if not detailed: return [os.path.join(remote_path, p) for p in list(flist.values())] else: return [ tuple( os.path.join(remote_path, dict(list(info.items()))['name']), {k: v for k, v in list(info.items()) if k != 'name'}) for info in list(flist.values()) ]
def upload_file(self, local_path, remote_path='A/', skip_checks=False): """ Upload a file to the device. :param local_paths: Path to a local file :type local_paths: str/unicode :param remote_path: Target path on the device :type remote_path: str/unicode :param skip_checks: Skip sanity checks on the device, required if a script is running on the device while uploading. """ # TODO: Test! local_path = os.path.abspath(local_path) remote_path = util.to_camerapath(remote_path) if os.path.isdir(local_path): raise ValueError("`local_path` must be a file, not a directory.") if not skip_checks: if remote_path.endswith("/"): try: status = parse_table( self._lua.call("con:stat", remote_path)) except LuaError: status = {'is_dir': False} if not status['is_dir']: raise ValueError("Remote path '{0}' is not a directory. " "Please leave out the trailing slash if " "you are refering to a file") remote_path = os.path.join(remote_path, os.path.basename(local_path)) self._lua.call("con:upload", local_path, remote_path)
def upload_file(self, local_path, remote_path="A/", skip_checks=False): """ Upload a file to the device. :param local_paths: Path to a local file :type local_paths: str/unicode :param remote_path: Target path on the device :type remote_path: str/unicode :param skip_checks: Skip sanity checks on the device, required if a script is running on the device while uploading. """ # TODO: Test! local_path = os.path.abspath(local_path) remote_path = util.to_camerapath(remote_path) if os.path.isdir(local_path): raise ValueError("`local_path` must be a file, not a directory.") if not skip_checks: if remote_path.endswith("/"): try: status = parse_table(self._lua.call("con:stat", remote_path)) except LuaError: status = {"is_dir": False} if not status["is_dir"]: raise ValueError( "Remote path '{0}' is not a directory. " "Please leave out the trailing slash if " "you are refering to a file" ) remote_path = os.path.join(remote_path, os.path.basename(local_path)) self._lua.call("con:upload", local_path, remote_path)
def mkdir(self, remote_path): """ Create a directory on the device. Intermediate directories will be created as needed. :param remote_path: Path on the device :type remote_path: str/unicode """ remote_path = util.to_camerapath(remote_path) self._lua.call("con:mkdir_m", remote_path)
def batch_upload(self, local_paths, remote_path="A/"): """ Upload multiple files/directories to the device. :param local_paths: Multiple locals paths :type local_paths: collection of str/unicode :param remote_path: Target path on the device :type remote_path: str/unicode """ remote_path = util.to_camerapath(remote_path) local_paths = [os.path.abspath(p) for p in local_paths] self._lua.call("con:mupload", self._lua.table(*local_paths), remote_path, dirs=True, mtime=True, maxdepth=100)
def batch_upload(self, local_paths, remote_path='A/'): """ Upload multiple files/directories to the device. :param local_paths: Multiple locals paths :type local_paths: collection of str/unicode :param remote_path: Target path on the device :type remote_path: str/unicode """ remote_path = util.to_camerapath(remote_path) local_paths = [os.path.abspath(p) for p in local_paths] self._lua.call("con:mupload", self._lua.table(*local_paths), remote_path, dirs=True, mtime=True, maxdepth=100)
def reboot(self, wait=3500, bootfile=None): """ Reboot the device. :param wait: Time in miliseconds to wait before attempting to reconnect :type wait: int :param bootfile: Optional file to boot. Must be the path to an existing file on the device that is either an unencoded binary or (for DryOS) an encoded .FI2 :type bootfile: str/unicode """ if bootfile: bootfile = util.to_camerapath(bootfile) self.lua_execute("sleep(1000); reboot('{0}')".format(bootfile), clobber=True) self.reconnect(wait)
def batch_download(self, remote_paths, local_path='./', overwrite=False): """ Download multiple files/directories from the device. :param remote_paths: Multiple paths on the device. The leading 'A/' is optional, it will be automatically prepended if not specified :type remote_paths: collection of str/unicode :param local_path: Target path on the local file system :type local_path: str/unicode :param overwrite: Overwrite existing files :type overwrite: bool """ remote_paths = [util.to_camerapath(p) for p in remote_paths] local_path = os.path.abspath(local_path) self._lua.call("con:mdownload", self._lua.table(*remote_paths), local_path, maxdepth=100, batchsize=20, dbgmem=False, overwrite=overwrite)
def list_files(self, remote_path='A/DCIM', detailed=False): """ Get directory listing for a path on the device. :param remote_path: Path on the device :type remote_path: str/unicode :param detailed: Return detailed information about each file/dir :type detailed: bool :return: All files and directories in the path """ remote_path = util.to_camerapath(remote_path) flist = self._lua.call("con:listdir", remote_path, dirsonly=False, stat="*" if detailed else "/") if not detailed: return [os.path.join(remote_path, p) for p in flist.values()] else: return [tuple(os.path.join(remote_path, dict(info.items())['name']), {k: v for k, v in info.items() if k != 'name'}) for info in flist.values()]
def download_file(self, remote_path, local_path=None): """ Download a single file from the device. If no local path is specified, the file's content is returned as a bytestring. :param remote_path: Path on the device. The leading 'A/' is optional, it will be automatically prepended if not specified :type remote_path: str/unicode :param local_path: (Optional) local path to store file under. :type local_path: str/unicode :return: If `local_path` was not specified, the file content as a bytestring, otherwise None :rtype: str/None """ remote_path = util.to_camerapath(remote_path) path = local_path or tempfile.mkstemp()[1] self._lua.call("con:download", remote_path, path) if not local_path: with open(path, 'rb') as fp: rval = fp.read() os.unlink(path) return rval
def download_file(self, remote_path, local_path=None): """ Download a single file from the device. If no local path is specified, the file's content is returned as a bytestring. :param remote_path: Path on the device. The leading 'A/' is optional, it will be automatically prepended if not specified :type remote_path: str/unicode :param local_path: (Optional) local path to store file under. :type local_path: str/unicode :return: If `local_path` was not specified, the file content as a bytestring, otherwise None :rtype: str/None """ remote_path = util.to_camerapath(remote_path) path = local_path or tempfile.mkstemp()[1] self._lua.call("con:download", remote_path, path) if not local_path: with open(path, "rb") as fp: rval = fp.read() os.unlink(path) return rval