In [1]:
%load_ext autoreload
%autoreload 2

In [2]:
from sync import *
from entities import *
import entities
from inventories import *
from sftpsession import *
import os
import pickle
load = lambda filename: pickle.load(open(filename+".pickle", "rb"))

In [3]:
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

In [4]:
r, l = load("remote"), load("local")
print(len(r), len(l))


(168383, 167784)

In [43]:
rf, lf = set(r.iterkeys()), set(l.iterkeys())
len(r), len(l)


Out[43]:
(168343, 251262)

In [56]:
added, deleted, modified = get_changes(r, rf, l, lf)

In [66]:
trash_deletions('C:/temp', {'foo/bar/baz', 'foo/bar/baz/f1', 'foo/fubar.txt'}, {'foo/bar/baz', 'foo/bar/baz/f1', 'foo'}, dry_run=True)


DEBUG:sync:Don't need to move: set(['foo/bar/baz/f1'])
NOTE:sync:WhatIf: renames(args=('C:/temp\\foo/fubar.txt', 'C:/temp\\.SyncTrash\\foo/fubar.txt'), kwargs=None)
NOTE:sync:WhatIf: renames(args=('C:/temp\\foo/bar/baz', 'C:/temp\\.SyncTrash\\foo/bar/baz'), kwargs=None)
INFO:sync:2 trash operations.

In [73]:
trash_deletions('O:/Backups/SEM/svn', deleted[0], deleted[1], dry_run=False)


INFO:root:Creating O:/Backups/SEM/svn\.SyncTrash for 83556 deletions
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

INFO:sync:83556 items moved to O:/Backups/SEM/svn\.SyncTrash.

In [99]:
added_items = added[0]
create_folders('O:/Backups/SEM/svn', added_items, r, False)


INFO:sync:Created 1 new folders

In [125]:
r.content["test.f"] = entities.FileEntity("test.f", ".", os.stat('C:/windows/notepad.exe'))

In [126]:
r["test.f"]


Out[126]:
<FileEntity(test.f)>

In [111]:
create_zero_files("C:/Temp", [entities.FileEntity("test.f", ".", os.stat("C:/temp"))], dry_run=False)


DEBUG:sync:Allocated C:\Temp\test.f (size 0, mtime 1537224092)

In [128]:
download_files("foo", "x", "y", "/", r, "C:/Temp", ["test.f"], dry_run=True)


INFO:sync:Downloading 1 files:
INFO:sync:WhatIf: Download C:\Temp\test.f, 254464 bytes
INFO:sync:Downloaded 254464 bytes in 1 files

In [127]:
[f for f in r.keys() if '.f' in f]


Out[127]:
['test.f']

In [ ]:
del s

In [3]:
s = SSHSession("dogfish.lan", "oliver", "df(V3r1l05t)")

In [5]:
rc, out = s.execute("cat", inputs="Rainy day.\nHello world\n\n", read_stdout=True, timeout=10)

In [7]:
out


Out[7]:
'Rainy day.\nHello world\n\n'

In [13]:
stdout.channel


Out[13]:
<paramiko.Channel 0 (closed) -> <paramiko.Transport at 0x631df98L (cipher aes128-ctr, 128 bits) (active; 0 open channel(s))>>

In [15]:
stdout.channel.exit_status_ready()


Out[15]:
True
ERROR:paramiko.transport:Socket exception: An existing connection was forcibly closed by the remote host (10054)

In [18]:
f = FileEntity("RobotDeployer_0.0.3.zip", DirectoryEntity("mods", DirectoryEntity(".", None)), 123, 123)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-4ea7db0f7d30> in <module>()
----> 1 f = FileEntity("RobotDeployer_0.0.3.zip", DirectoryEntity("mods", DirectoryEntity(".", None)), 123, 123)

TypeError: __init__() takes exactly 4 arguments (3 given)

In [4]:
d = DirectoryEntity("mods", None, None)
fn = "RobotDeployer_0.0.3.zip"
f = FileEntity(fn, d, os.stat("c:/users/oliver/appdata/roaming/factorio/mods/"+fn))
remote_inv = { "mods": d, "mods/"+fn: f }

In [10]:
test_checksums("dogfish", "oliver", "df(V3r1l05t)", "/opt/factorio", "c:/users/oliver/appdata/roaming/factorio", remote_inv, ["mods/"+fn])


DEBUG:sync:SSHClient: Connecting to dogfish with oliver and password
DEBUG:paramiko.transport:starting thread (client mode): 0x6b9d438L
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.4.1
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_7.6p1 Ubuntu-4
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_7.6p1)
DEBUG:paramiko.transport:kex algos:[u'curve25519-sha256', u'curve25519-sha256@libssh.org', u'ecdh-sha2-nistp256', u'ecdh-sha2-nistp384', u'ecdh-sha2-nistp521', u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group16-sha512', u'diffie-hellman-group18-sha512', u'diffie-hellman-group14-sha256', u'diffie-hellman-group14-sha1'] server key:[u'ssh-rsa', u'rsa-sha2-512', u'rsa-sha2-256', u'ecdsa-sha2-nistp256', u'ssh-ed25519'] client encrypt:[u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com'] server encrypt:[u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com'] client mac:[u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'] server mac:[u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: ecdh-sha2-nistp256
DEBUG:paramiko.transport:HostKey agreed: ssh-ed25519
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexNistp256 specified hash_algo <built-in function openssl_sha256>
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ssh-ed25519 host key for dogfish: 5d2c223281ce88acaa2da5a6ff651b0b
DEBUG:paramiko.transport:Trying SSH agent key c021d56c23743ee999bd1374919a9d66
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (publickey) failed.
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
INFO:sync:Fetching 1 local checksums
INFO:sync:Fetching 1 remote checksums
DEBUG:sync:Waiting on worker threads
DEBUG:sync:Local checksums retrieved
DEBUG:sync:cd '/opt/factorio' && xargs -0 md5sum --binary
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:Received global request "hostkeys-00@openssh.com"
DEBUG:paramiko.transport:Rejecting "hostkeys-00@openssh.com" global request from server.
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] EOF sent (0)
DEBUG:paramiko.transport:[chan 0] EOF received (0)
DEBUG:sync:Remote checksums retrieved
DEBUG:sync:Shutting down SSH session
DEBUG:paramiko.transport:EOF in transport thread
INFO:sync:Remote hashes completed
INFO:sync:Local hashes completed
Out[10]:
set()

In [34]:
f


Out[34]:
<FileEntity(RobotDeployer_0.0.3.zip)>

In [35]:
dir(f)


Out[35]:
['__class__',
 '__delattr__',
 '__dict__',
 '__doc__',
 '__format__',
 '__getattribute__',
 '__hash__',
 '__init__',
 '__module__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 'differs',
 'md5sum',
 'mtime',
 'name',
 'parent',
 'size']

In [36]:
f.md5sum


Out[36]:
'91e2c7399b9ea1e28fa89d7b233bf404'

In [ ]: