Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
import json
import time
import os
import re
import shutil
import sys
import threading
import subprocess

return_values = []
immutable = None
retain_until = None

def copyfile(src, dst):
    try:
        os.makedirs(os.path.dirname(dst), 0o755)
    except Exception as ex:
        print(ex)

    try:
        shutil.copyfile(src, dst)
        if immutable:
            workload_db_pattern = re.search("workload_[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}/workload_db", dst)
            workload_vms_db_pattern = re.search("workload_[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}/workload_vms_db", dst)
            time.sleep(2)
            if not (workload_db_pattern or \
                workload_vms_db_pattern):
                subprocess.call(
                    ['setfattr',
                    '-n', 'stamp-trilio-authenticity',
                    '-v', 'True',
                    dst])
                subprocess.call(
                    ['setfattr',
                    '-n', 'retainuntil',
                    '-v', retain_until,
                    dst])
    except Exception as ex:
        print(ex)
        return_values.append(2)

if __name__ == "__main__":
    print(sys.argv)

    if len(sys.argv) != 4:
        print("Usage: pcopy <filestocopy>")
        sys.exit(1)

    path = sys.argv[1]

    if sys.argv[2] in ['True', 'true', True]:
        immutable = True
        retain_until = sys.argv[3]

    if not os.path.exists(path) or not os.path.isfile(path):
        print("%s must be a file" % path)
        sys.exit(1)

    with open(path, "r") as f:
        x = json.load(f)

    threads = []
    for i in x:
        t = threading.Thread(target=copyfile, args=i)
        t.start()
        threads.append(t)

    for i in threads:
        i.join()

    if len(return_values):
        sys.exit(1)
    else:
        sys.exit(0)