That's very easy to do in python itself.
The script below copies all files *.py from a source directory to a target directory (excluding the unit tests), and it deletes the files that aren't found (I had issues once after renaming a file and keeping the old code around too, didn't understand my own error messages). It happens async, so it's pretty fast and to ignition, the files are updated almost at the same time, so everything gets loaded at the same time (you don't want a client hitting the "update" bar while only half of the files are updated).
def SendToIgnition(targetDir, sourceDir):
print("copy from " + sourceDir + " to " + targetDir)
foundFiles = []
threads = []
for subDir, dir, files in os.walk(sourceDir):
for filename in files:
path = os.path.join(subDir, filename)
if path.endswith(".py") and not filename.startswith("test_"):
relFile = path[len(sourceDir) + 1:]
foundFiles.append(relFile)
print("copy file " + relFile)
targetFile = os.path.join(targetDir, relFile)
if not os.path.exists(os.path.dirname(targetFile)):
os.mkdir(os.path.dirname(targetFile))
threads.append(threading.Thread(
target=shutil.copy,
args=(os.path.join(sourceDir, relFile), targetFile)
))
for t in threads:
t.start()
for t in threads:
t.join()
print "Coyping done"
for subDir, dir, files in os.walk(targetDir):
for filename in files:
path = os.path.join(subDir, filename)
relFile = path[len(targetDir) + 1:]
if not (relFile in foundFiles):
try:
if path.endswith(".py"):
print("remove file " + relFile)
os.remove(os.path.join(targetDir, relFile))
except:
print("Failed to delete file" + relFile)
To copy it to a different server, I share the pylib folder from Windows (on Linux you could make an SSH connection), and I can copy a library like this, from a file placed next to the library.
sourceDir = os.path.directory(__file__)
targetDir = "\\\\hostname\\pylib"
folder = "libraryName"
# Connect to shared drive using a local account
subprocess.call('net use %s /user:127.0.0.1\\UserName P@SSW0RD' % targetDir, shell=True)
SendToIgnition(os.path.join(targetDir, libraryName), os.path.join(sourceDir, libraryName))
If you use an IDE with an interpreter, you can just run that python script from inside your IDE, and it will get synced.