|
41 | 41 | secret_key=environ.get('S3_SECRET_KEY', 'datajoint'), |
42 | 42 | bucket=environ.get('S3_BUCKET', 'datajoint-test')) |
43 | 43 |
|
| 44 | +S3_MIGRATE_BUCKET = [path.stem for path in Path( |
| 45 | + Path(__file__).resolve().parent, |
| 46 | + 'external-legacy-data', 's3').iterdir()][0] |
| 47 | + |
44 | 48 | # Prefix for all databases used during testing |
45 | 49 | PREFIX = environ.get('DJ_TEST_DB_PREFIX', 'djtest') |
46 | 50 | conn_root = dj.conn(**CONN_INFO_ROOT) |
@@ -129,23 +133,22 @@ def setup_package(): |
129 | 133 | source = Path( |
130 | 134 | Path(__file__).resolve().parent, |
131 | 135 | 'external-legacy-data','s3') |
132 | | - bucket = "migrate-test" |
133 | 136 | region = "us-east-1" |
134 | 137 | try: |
135 | | - minioClient.make_bucket(bucket, location=region) |
| 138 | + minioClient.make_bucket(S3_MIGRATE_BUCKET, location=region) |
136 | 139 | except minio.error.BucketAlreadyOwnedByYou: |
137 | 140 | pass |
138 | 141 |
|
139 | 142 | pathlist = Path(source).glob('**/*') |
140 | 143 | for path in pathlist: |
141 | 144 | if os.path.isfile(str(path)) and ".sql" not in str(path): |
142 | 145 | minioClient.fput_object( |
143 | | - bucket, str(Path( |
144 | | - os.path.relpath(str(path),str(Path(source,bucket)))) |
| 146 | + S3_MIGRATE_BUCKET, str(Path( |
| 147 | + os.path.relpath(str(path),str(Path(source,S3_MIGRATE_BUCKET)))) |
145 | 148 | .as_posix()), str(path)) |
146 | 149 | # Add S3 |
147 | 150 | try: |
148 | | - minioClient.make_bucket("datajoint-test", location=region) |
| 151 | + minioClient.make_bucket(S3_CONN_INFO['bucket'], location=region) |
149 | 152 | except minio.error.BucketAlreadyOwnedByYou: |
150 | 153 | pass |
151 | 154 |
|
@@ -176,19 +179,17 @@ def teardown_package(): |
176 | 179 | remove("dj_local_conf.json") |
177 | 180 |
|
178 | 181 | # Remove old S3 |
179 | | - bucket = "migrate-test" |
180 | 182 | objs = list(minioClient.list_objects_v2( |
181 | | - bucket, recursive=True)) |
182 | | - objs = [minioClient.remove_object(bucket, |
| 183 | + S3_MIGRATE_BUCKET, recursive=True)) |
| 184 | + objs = [minioClient.remove_object(S3_MIGRATE_BUCKET, |
183 | 185 | o.object_name.encode('utf-8')) for o in objs] |
184 | | - minioClient.remove_bucket(bucket) |
| 186 | + minioClient.remove_bucket(S3_MIGRATE_BUCKET) |
185 | 187 |
|
186 | 188 | # Remove S3 |
187 | | - bucket = "datajoint-test" |
188 | | - objs = list(minioClient.list_objects_v2(bucket, recursive=True)) |
189 | | - objs = [minioClient.remove_object(bucket, |
| 189 | + objs = list(minioClient.list_objects_v2(S3_CONN_INFO['bucket'], recursive=True)) |
| 190 | + objs = [minioClient.remove_object(S3_CONN_INFO['bucket'], |
190 | 191 | o.object_name.encode('utf-8')) for o in objs] |
191 | | - minioClient.remove_bucket(bucket) |
| 192 | + minioClient.remove_bucket(S3_CONN_INFO['bucket']) |
192 | 193 |
|
193 | 194 | # Remove old File Content |
194 | 195 | shutil.rmtree(str(Path(os.path.expanduser('~'),'temp'))) |
0 commit comments