()
| 33 | |
| 34 | |
| 35 | def main(): |
| 36 | with enterprise.LicenseCheckout(): |
| 37 | if len(sys.argv) < 2: |
| 38 | print(f"Usage: {sys.argv[0]} <remote name> <project name>") |
| 39 | print("") |
| 40 | print("Here is a list of remotes available to you:") |
| 41 | for remote in sorted(collaboration.known_remotes(), key=lambda remote: remote.name): |
| 42 | print(f"{remote.name}") |
| 43 | sys.exit(1) |
| 44 | |
| 45 | # Connect to remote as specified |
| 46 | remote = collaboration.get_remote_by_name(sys.argv[1]) |
| 47 | if not remote: |
| 48 | return |
| 49 | if not remote.is_connected: |
| 50 | # Will pull default credentials from either Enterprise or Keychain |
| 51 | remote.connect() |
| 52 | |
| 53 | if len(sys.argv) < 3: |
| 54 | print(f"Usage: {sys.argv[0]} <remote name> <project name>") |
| 55 | print("") |
| 56 | print("Here is a list of projects available to you:") |
| 57 | for project in sorted(remote.projects, key=lambda project: project.name): |
| 58 | print(f"{project.name}") |
| 59 | sys.exit(1) |
| 60 | |
| 61 | # Create test project |
| 62 | project = remote.get_project_by_name(sys.argv[2]) |
| 63 | if project is None: |
| 64 | print(f"Creating new project '{sys.argv[2]}'") |
| 65 | project = remote.create_project(sys.argv[2], "") |
| 66 | |
| 67 | known_hashes = set() |
| 68 | project.pull_folders() |
| 69 | for file in project.files: |
| 70 | known_hashes.add(file.hash.lower()) |
| 71 | |
| 72 | # Find all the files in the current directory and upload them |
| 73 | for file in tqdm(list(sorted(Path(os.curdir).rglob("*"))), desc="Files"): |
| 74 | if not file.is_file(): |
| 75 | continue |
| 76 | if file.name == ".DS_Store": |
| 77 | continue |
| 78 | try: |
| 79 | # Check sha256 |
| 80 | with open(file, 'rb') as f: |
| 81 | hash = hashlib.sha256(f.read()).hexdigest() |
| 82 | if hash.lower() in known_hashes: |
| 83 | continue |
| 84 | |
| 85 | # Create parents |
| 86 | base = Path(os.curdir) |
| 87 | parents = [] |
| 88 | parent = file.parent |
| 89 | while parent != base and parent is not None: |
| 90 | parents.insert(0, parent.name) |
| 91 | parent = parent.parent |
| 92 |
no test coverage detected