- May 11, 2008
- 20,648
- 1,171
- 126
Hi.
There is something i am not sure about.
The shutil.copytree function copies folder and files in a tree.
When looking into I keeps track and gathers all the errors.
But does this mean that shutil.copytree just copies all files that are not raising exceptions ?
I wrote this code to copy the /usr/lib/arm-linux-gnueabihf directory and files to an usb stick.
And at the same time, the symlinks are resolved.
After that from the destination, the duplicate libraries are removed.
This keeps the destination directory small.
Also, how do i retreive the errors that i can print them while keeping the script going instead ?
There is something i am not sure about.
The shutil.copytree function copies folder and files in a tree.
When looking into I keeps track and gathers all the errors.
But does this mean that shutil.copytree just copies all files that are not raising exceptions ?
I wrote this code to copy the /usr/lib/arm-linux-gnueabihf directory and files to an usb stick.
And at the same time, the symlinks are resolved.
After that from the destination, the duplicate libraries are removed.
This keeps the destination directory small.
Also, how do i retreive the errors that i can print them while keeping the script going instead ?
Code:
import os
import sys
import shutil
print "Python interpreter version"
print (sys.version)
print "Getlib script version 0.1"
libsource_path = "usr/lib/"
usbpathname = raw_input("Please enter the path of the usb stick : ")
print ("Path = " + usbpathname)
print ("Accessing usb stick")
status = os.lstat(usbpathname)
print status
print ("Done.")
destinationpath = usbpathname + "/rpi_warmlibs/arm-linux-gnueabihf/"
print ("Destination path is : " + destinationpath)
print ("Creating directory on usb stick and copying files from /usr/lib/arm-linux-gnueabihf to" + destinationpath)
print "Symlinks will be changed to original files"
print "Please wait..."
try:
shutil.copytree('/usr/lib/arm-linux-gnueabihf', destinationpath, symlinks=False)
except OSError:
print (" Few maps or files that already exists where discovered and are probably a duplicate because of the symlink resolving")
print "Done :)"
print "Finished copying"
removepath = destinationpath
print ("Removing double files from : " + removepath)
dirsandfiles = os.listdir(removepath)
for file in dirsandfiles:
pathandfile = removepath + file
if os.path.isfile(pathandfile):
print ("Found file : " + file)
if not( file.endswith('.a') or file.endswith('.so')):
print ("Removing file : " + file)
os.remove(pathandfile)