Have been interested for python script and finally i got a chance to play with it.

So the mission for today is to create the write and delete test for my environment.

Local machine ¬†—-COPY—> ¬†Mounted filesystem in NAS

Why i am doing so? to get a baseline for my write and delete operation.I will make use of “time” command to get total runtime for the script to complete the operation. So here goes the simple script(Feel free to provide your code if you have idea, i am a noob in python:) )

BTW, Nanako is just an echo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
import os
import shutil
 
#set source path & file name
src = "/usr2/"
file_name = "testfile.txt"
source_file_path = src + file_name
 
#set destination path
dest = "/data/tingwei/test_copy/"
 
#set number of copies for the copying progress
copies = 1000
dir_copies = 10
 
for x in range(dir_copies):
    dirname = dest + str(x)
    if not os.path.isdir(dirname):
        os.mkdir(dirname)
        print "Nanako: mkdir " + str(dirname)
#start progress
        print "Nanako: Ready to copy " + `copies` + " files."
        for i in range(copies):
                new_file_name = file_name + `i`
                dest_file_path = dirname + "/" + new_file_name
                shutil.copyfile (source_file_path, dest_file_path)
 
print "Nanako: Done copying " + `copies` + " files."
print "Nanako: Preparing to cleanup " + dest
 
#this line is to remove the files & directories created
for x in os.listdir(dest):
   shutil.rmtree(os.path.join(dest,x))
 
#just in case you want to see is there any left over in the destination
def listdir_fullpath(d):
    return [os.path.join(d, f) for f in os.listdir(d)]
 
for i in listdir_fullpath(dest):
    print i