コード例 #1
0
ファイル: sync.py プロジェクト: breez7/TeslaCam
def upload_for_smb(root, paths, target_path, checkpoint):
    if len(paths) == 0:
        return

    for path in paths:
        print('send path : ' + path)
        try:
            smbclient.mkdir(target_path + '/' + path,username=username, password=password, port=smb_port)
        except:
            pass
        
        send_files = get_event_files(root, path)
        for send_file in send_files:
            try:
                smbclient.stat(target_path + '/' + path + '/' + send_file.split('/')[-1],username=username, password=password, port=smb_port)
            except:
                print('sending ' + send_file)
                dest = smbclient.open_file(target_path+'/'+path+'/'+send_file.split('/')[-1], 'wb',username=username, password=password, port=smb_port)
                src = open(send_file, 'rb')
                while True:
                    temp = src.read(1024 * 4)
                    if len(temp) == 0:
                        break
                    dest.write(temp)
                src.close()
                dest.close()

    make_checkpoint(paths, checkpoint)
コード例 #2
0
 def _rm(self, path):
     if _share_has_path(path):
         wpath = _as_unc_path(self.host, path)
         stats = smbclient.stat(wpath)
         if S_ISDIR(stats.st_mode):
             smbclient.rmdir(wpath)
         else:
             smbclient.remove(wpath)
コード例 #3
0
 def info(self, path, **kwargs):
     wpath = _as_unc_path(self.host, path)
     stats = smbclient.stat(wpath, **kwargs)
     if S_ISDIR(stats.st_mode):
         stype = "directory"
     elif S_ISLNK(stats.st_mode):
         stype = "link"
     else:
         stype = "file"
     res = {
         "name": path + "/" if stype == "directory" else path,
         "size": stats.st_size,
         "type": stype,
         "uid": stats.st_uid,
         "gid": stats.st_gid,
         "time": stats.st_atime,
         "mtime": stats.st_mtime,
     }
     return res
コード例 #4
0
ファイル: samba.py プロジェクト: youngyjd/incubator-airflow
 def stat(self, path, follow_symlinks=True):
     return smbclient.stat(self._join_path(path), follow_symlinks=follow_symlinks, **self._conn_kwargs)
コード例 #5
0
 def modified(self, path):
     """Return the modified timestamp of a file as a datetime.datetime"""
     wpath = _as_unc_path(self.host, path)
     stats = smbclient.stat(wpath)
     return datetime.datetime.utcfromtimestamp(stats.st_mtime)
コード例 #6
0
# Optional - register the server with explicit credentials
register_session("server", username="******", password="******")

# Read an existing file as text (credentials only needed for the first request to the server if not registered.)
with open_file(r"\\server\share\file.txt", username="******", password="******") as fd:
    file_contents = fd.read()

# Read an existing file as bytes
with open_file(r"\\server\share\file.txt", mode="rb") as fd:
    file_bytes = fd.read()

# Create a file and write to it
with open_file(r"\\server\share\file.txt", mode="w") as fd:
    fd.write(u"content")

# Write data to the end of an existing file
with open_file(r"\\server\share\file.txt", mode="a") as fd:
    fd.write(u"\ndata at the end")

# Delete a file
remove(r"\\server\share\file.txt")

# Get info about a file
stat(r"\\server\share\file.txt")

# Create a symbolic link
symlink(r"\\server\share\directory", r"\\server\share\link")

# Create a hard link
link(r"\\server\share\file.txt", r"\\server\share\hard-link.txt")
コード例 #7
0
 def _getStat(self) -> os.stat_result:
     if not self._cachedStat:
         self._cachedStat = smbclient.stat(self.fileFullPath)
     return self._cachedStat
コード例 #8
0
ファイル: backend.py プロジェクト: Timtam/bookstone
    def getStats(self, path: str) -> Any:

        return smbclient.stat(path, username=self._username, password=self._password)