Skip to content

Commit 0064a2d

Browse files
authored
Updated CI cfg (#164)
* Updated CI cfg * Updated sftp example
1 parent 4996524 commit 0064a2d

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

.circleci/config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ jobs:
122122
./ci/build-manylinux.sh
123123
- run:
124124
name: sdist
125-
command: python setup.py sdist
125+
command: |
126+
sudo chown circleci -R *
127+
python setup.py sdist
126128
- run:
127129
name: Upload Wheels
128130
command: |

examples/sftp_write.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
"""Example script for SFTP write"""
44

5-
from __future__ import print_function
6-
75
import argparse
86
import socket
97
import os
10-
import pwd
11-
import sys
128
from datetime import datetime
139

1410
from ssh2.session import Session
@@ -17,7 +13,7 @@
1713
LIBSSH2_SFTP_S_IROTH
1814

1915

20-
USERNAME = pwd.getpwuid(os.geteuid()).pw_name
16+
USERNAME = os.getlogin()
2117

2218
parser = argparse.ArgumentParser()
2319

@@ -32,6 +28,7 @@
3228

3329

3430
def main():
31+
buf_size = 1024 * 1024
3532
args = parser.parse_args()
3633
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3734
sock.connect((args.host, args.port))
@@ -40,18 +37,23 @@ def main():
4037
s.agent_auth(args.user)
4138
sftp = s.sftp_init()
4239
mode = LIBSSH2_SFTP_S_IRUSR | \
43-
LIBSSH2_SFTP_S_IWUSR | \
44-
LIBSSH2_SFTP_S_IRGRP | \
45-
LIBSSH2_SFTP_S_IROTH
40+
LIBSSH2_SFTP_S_IWUSR | \
41+
LIBSSH2_SFTP_S_IRGRP | \
42+
LIBSSH2_SFTP_S_IROTH
4643
f_flags = LIBSSH2_FXF_CREAT | LIBSSH2_FXF_WRITE
44+
fileinfo = os.stat(args.source)
4745
print("Starting copy of local file %s to remote %s:%s" % (
4846
args.source, args.host, args.destination))
4947
now = datetime.now()
50-
with open(args.source, 'rb') as local_fh, \
48+
with open(args.source, 'rb', buf_size) as local_fh, \
5149
sftp.open(args.destination, f_flags, mode) as remote_fh:
52-
for data in local_fh:
50+
data = local_fh.read(buf_size)
51+
while data:
5352
remote_fh.write(data)
54-
print("Finished writing remote file in %s" % (datetime.now() - now,))
53+
data = local_fh.read(buf_size)
54+
taken = datetime.now() - now
55+
rate = (fileinfo.st_size / 1024000.0) / taken.total_seconds()
56+
print(f"Finished writing remote file in {taken}, transfer rate {rate} MB/s")
5557

5658

5759
if __name__ == "__main__":

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tag_prefix = ''
88
universal = 0
99

1010
[flake8]
11-
max-line-length = 80
11+
max-line-length = 100
1212
filename = *.pyx,*.px*
1313
exclude = .eggs,*.egg,build
1414
ignore = E901,E225,E226,E227,E999

0 commit comments

Comments
 (0)