summaryrefslogtreecommitdiffstats
path: root/glustolibs-io/shared_files/scripts/fd_writes.py
diff options
context:
space:
mode:
authorValerii Ponomarov <vponomar@redhat.com>2019-11-26 21:28:20 +0530
committerValerii Ponomarov <vponomar@redhat.com>2019-12-02 20:07:31 +0530
commit50453885291f5c5341ceb3a732be9a068873cffe (patch)
tree6597405e6b6052adff32fc166922e7e07f8369f3 /glustolibs-io/shared_files/scripts/fd_writes.py
parent08b727842bc66603e3b8d1160ee4b15051b0cd20 (diff)
[py2to3] Fix files located in the 'glustolibs-io' dir
Do following things in the files from the mentioned directory: - Make it be python 2/3 compatible. - Fix pep8 issues. - Place imports in alphabetical order. - Improve some parts for the better readability. - Add comma separators in the setup.py for it's classifiers. Before it was mistakenly made as one long line. Change-Id: I3f0a5921a5386275a8a35bf2f22ee3952700e490 Signed-off-by: Valerii Ponomarov <kiparis.kh@gmail.com>
Diffstat (limited to 'glustolibs-io/shared_files/scripts/fd_writes.py')
-rwxr-xr-xglustolibs-io/shared_files/scripts/fd_writes.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/glustolibs-io/shared_files/scripts/fd_writes.py b/glustolibs-io/shared_files/scripts/fd_writes.py
index c909304..e3ebccb 100755
--- a/glustolibs-io/shared_files/scripts/fd_writes.py
+++ b/glustolibs-io/shared_files/scripts/fd_writes.py
@@ -17,13 +17,13 @@
from __future__ import print_function
import argparse
-import random
-import os
-import time
-import string
import datetime
from multiprocessing import Process
+import os
+import random
+import string
import sys
+import time
def is_root(path):
@@ -80,15 +80,14 @@ def create_dir(dir_path):
def fd_write_file(filename, file_size, chunk_sizes_list, write_time,
delay_between_writes=10, log_level='INFO'):
- """Write random data to the file until write_time
- """
+ """Write random data to the file until write_time."""
rc = 0
time_counter = 0
try:
fd = open(filename, "w+b")
- fd.seek(file_size-1)
- fd.write("0")
+ fd.seek(file_size - 1)
+ fd.write(bytes(str("0").encode("utf-8")))
fd.flush()
except IOError as e:
print("Unable to open file %s for writing : %s" % (
@@ -109,7 +108,7 @@ def fd_write_file(filename, file_size, chunk_sizes_list, write_time,
filename, actual_file_size, offset, len(write_data),
time_counter))
fd.seek(offset)
- fd.write(write_data)
+ fd.write(bytes(str(write_data).encode("utf-8")))
fd.seek(0)
fd.flush()
except IOError as e:
@@ -130,11 +129,11 @@ def fd_writes(args):
base_file_name = args.base_file_name
file_sizes_list = args.file_sizes_list
if file_sizes_list:
- file_sizes_list = filter(None, args.file_sizes_list.split(","))
+ file_sizes_list = list(filter(None, args.file_sizes_list.split(",")))
chunk_sizes_list = args.chunk_sizes_list
if chunk_sizes_list:
- chunk_sizes_list = map(int, filter(None,
- args.chunk_sizes_list.split(",")))
+ chunk_sizes_list = list(
+ map(int, filter(None, args.chunk_sizes_list.split(","))))
write_time = int(args.write_time)
delay_between_writes = int(args.delay_between_writes)
log_level = args.log_level
@@ -151,11 +150,11 @@ def fd_writes(args):
file_sizes_dict = {
'k': 1024,
'K': 1024,
- 'm': 1024*1024,
- 'M': 1024*1024,
- 'g': 1024*1024*1024,
- 'G': 1024*1024*1024
- }
+ 'm': 1024 ** 2,
+ 'M': 1024 ** 2,
+ 'g': 1024 ** 3,
+ 'G': 1024 ** 3,
+ }
file_sizes_expanded_list = []
for size in file_sizes_list: