|
4 | 4 | from datetime import datetime |
5 | 5 |
|
6 | 6 | from FileService import is_file_directory_writable, is_file_writable |
7 | | -from defines import FlattenLevel, CollisionStrategy |
| 7 | +from defines import FlattenLevel, RenameStrategy, CollisionAction, ProviderType |
8 | 8 | import argparse |
9 | 9 |
|
10 | 10 |
|
| 11 | +# TODO: prioritize argument to give priority |
11 | 12 | def build_argument_parser(): |
12 | 13 | parser = argparse.ArgumentParser(description="Backup your git repos in your local filesystem") |
13 | 14 |
|
@@ -71,19 +72,41 @@ def build_argument_parser(): |
71 | 72 | nargs="+", |
72 | 73 | dest="flatten_directories", |
73 | 74 | choices=[name for name in FlattenLevel]) |
74 | | - parser.add_argument("-l", "--handle-collision", "--handle-collision-strategy", |
75 | | - help="Strategy to follow to handle collisions (a repo that because of its name has to be cloned" |
76 | | - " in the same folder path as another one):" + |
77 | | - CollisionStrategy.RENAME.name + ": Use a systematic name (the shortest possible) for the " |
78 | | - "new repo that produces the collision" + |
79 | | - CollisionStrategy.SYSTEMATIC.name + ": Use a systematic name for all repos" + |
80 | | - CollisionStrategy.IGNORE.name + ": Ignores repos that have filename collisions." + |
81 | | - CollisionStrategy.REMOVE.name + ": Removes the repo already cloned and clones the new one " |
82 | | - "with the same name.", |
| 75 | + parser.add_argument("-R", "--rename", "--rename-strategy", |
| 76 | + help="Strategy to rename the path to clone a repositories that has same path as " |
| 77 | + "another:" + |
| 78 | + RenameStrategy.SHORTEST.name + ": Use the shortest systematic name that avoids same path" |
| 79 | + "for the repo where the same path is detected." + |
| 80 | + RenameStrategy.SHORTEST_SYSTEMATIC.name + ": Use the shortest systematic name that avoids " |
| 81 | + "same path for both repos that produce the " |
| 82 | + "same path." + |
| 83 | + RenameStrategy.SYSTEMATIC.name + ": Use the full systematic name for all repos with " |
| 84 | + "the same path." + |
| 85 | + RenameStrategy.IGNORE.name + ": If a repo is found with the same clone path as another, do" |
| 86 | + " not clone the repo where the " |
| 87 | + "path coincidence is detected.", |
| 88 | + type=str, |
| 89 | + nargs='?', |
| 90 | + dest="rename_strategy", |
| 91 | + choices=[name for name in RenameStrategy]) |
| 92 | + parser.add_argument("-S", "--collision", "--collision-strategy", "--collision-action", |
| 93 | + help="Strategy to follow when finding a repo already cloned in the path that another repo is " |
| 94 | + "supposed to be cloned" + |
| 95 | + CollisionAction.FULL_UPDATE.name + ": If the new repo to be cloned is different than the " |
| 96 | + "one already cloned, remove the one already cloned and" |
| 97 | + "clone the new one in its place, if not, update the " |
| 98 | + "repo already cloned." + |
| 99 | + CollisionAction.UPDATE.name + ": Ignore the new repo to be cloned and updates the repo " |
| 100 | + "already cloned." + |
| 101 | + CollisionAction.IGNORE.name + ": Ignore the new repo to be cloned and do nothing." |
| 102 | + "." + |
| 103 | + CollisionAction.REMOVE.name + ": Remove the repo already cloned and clone the new one in " |
| 104 | + "the same path.", |
83 | 105 | type=str, |
84 | 106 | nargs='?', |
85 | 107 | dest="collision_strategy", |
86 | | - choices=[name for name in CollisionStrategy]) |
| 108 | + default=CollisionAction.FULL_UPDATE, |
| 109 | + choices=[name for name in CollisionAction]) |
87 | 110 | parser.add_argument("-j", "--json", "--generate-json", "--produce-json", |
88 | 111 | help="Generates a JSON report of the backup folders and repos.", |
89 | 112 | # type=bool, |
@@ -177,18 +200,18 @@ def parse_arguments(parser: argparse.ArgumentParser): |
177 | 200 | # When keeping the complete hierarchy we ensure that there will be no collisions |
178 | 201 | if not args.flatten_directories \ |
179 | 202 | and args.reflect_hierarchy \ |
180 | | - and args.collision_strategy: |
181 | | - parser.error("You do not need to supply a collision strategy with -l when keeping the hierarchy with -y and not" |
| 203 | + and args.rename_strategy: |
| 204 | + parser.error("You do not need to supply a rename strategy with -R when keeping the hierarchy with -y and not" |
182 | 205 | " flattening any directory (not supplying -F)") |
183 | 206 |
|
184 | 207 | # Supply default collision strategy if needed |
185 | 208 | if args.reflect_hierarchy \ |
186 | 209 | and args.flatten_directories \ |
187 | | - and not args.collision_strategy: |
188 | | - args.collision_strategy = "rename" |
| 210 | + and not args.rename_strategy: |
| 211 | + args.rename_strategy = RenameStrategy.SHORTEST_SYSTEMATIC |
189 | 212 |
|
190 | | - if not args.collision_strategy: |
191 | | - args.collision_strategy = "rename" |
| 213 | + if not args.rename_strategy: |
| 214 | + args.rename_strategy = RenameStrategy.SHORTEST_SYSTEMATIC |
192 | 215 |
|
193 | 216 | # If path supplied -c implicit |
194 | 217 | if not args.produce_compressed and args.compressed_path: |
@@ -231,7 +254,7 @@ def parse_arguments(parser: argparse.ArgumentParser): |
231 | 254 | custom_providers = [] |
232 | 255 | for custom_provider in args.custom_providers: |
233 | 256 | if args.exclude_github: |
234 | | - custom_providers.append({'url': custom_provider, 'provider': "GitLab"}) |
| 257 | + custom_providers.append({'url': custom_provider, 'provider': ProviderType.GITLAB}) |
235 | 258 | if args.exclude_gitlab: |
236 | | - custom_providers.append({'url': custom_provider, 'provider': "GitHub"}) |
| 259 | + custom_providers.append({'url': custom_provider, 'provider': ProviderType.GITHUB}) |
237 | 260 | return args |
0 commit comments