Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Copying script #10

Merged
merged 1 commit into from

1 participant

@fabienrohrer
Collaborator

Added a script allowing to copy all the files and directory recursively to Webots. This helps for synchronization.

@fabienrohrer fabienrohrer merged commit cb49824 into darwinop:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2012
  1. @fabienrohrer

    Added a script allowing to copy all the files and directory recursive…

    fabienrohrer authored
    …ly to Webots. This helps for synchronization.
This page is out of date. Refresh to see the latest.
Showing with 61 additions and 0 deletions.
  1. +61 −0 copy.py
View
61 copy.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+# Description: copy all the files inside the script directory to the destination directory
+# Author: fabien.rohrer@cyberbotics.com
+# Date: 3th October 2012
+
+import sys, os, os.path, inspect, shutil
+
+
+def scriptdirectory():
+ return os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
+
+
+def help():
+ print 'description: copy all the files inside the script directory to the destination directory'
+ print 'usage: ' + sys.argv[0] + ' destination_directory'
+
+
+if len(sys.argv) != 2:
+ help()
+ sys.exit(-1)
+
+if not os.path.exists(sys.argv[1]):
+ sys.stderr.write('Destination directory doesn\'t exits\n')
+ help()
+ sys.exit(-1)
+
+scriptdirectoryfullpath = scriptdirectory()
+scriptdirectorylength = len(scriptdirectoryfullpath)
+
+# parse all directories and files of the script directory
+for dirname, dirnames, filenames in os.walk(scriptdirectoryfullpath):
+ # for each directory
+ for subdirname in dirnames:
+ # generate the pathes
+ directoryfullpath = os.path.join(dirname, subdirname)
+ directoryrelativepath = directoryfullpath[scriptdirectorylength+1:]
+ destinationfullpath = os.path.join(sys.argv[1], directoryrelativepath)
+
+ # remove exceptions
+ if ".git" in directoryrelativepath: continue
+ if os.path.basename(sys.argv[0]) in directoryrelativepath: continue
+
+ # create the directory if required
+ if not os.path.exists(destinationfullpath):
+ os.makedirs(destinationfullpath)
+
+ # parse each file
+ for filename in filenames:
+ # generate the pathes
+ filefullpath = os.path.join(dirname, filename)
+ filerelativepath = filefullpath[scriptdirectorylength+1:]
+ destinationfullpath = os.path.join(sys.argv[1], filerelativepath)
+
+ # remove exceptions
+ if "README" in filerelativepath: continue
+ if ".git" in filerelativepath: continue
+ if os.path.basename(sys.argv[0]) in filerelativepath: continue
+
+ # copy the file
+ shutil.copyfile(filefullpath, destinationfullpath)
Something went wrong with that request. Please try again.