Skip to content

Commit cc6dd86

Browse files
committed
Black/isort syntax
1 parent 89daa12 commit cc6dd86

9 files changed

+212
-78
lines changed

alws/crud/products.py

+53-19
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ async def create_product(
7171
(
7272
await db.execute(
7373
select(models.Platform).where(
74-
models.Platform.name.in_([platform.name for platform in payload.platforms]),
74+
models.Platform.name.in_(
75+
[platform.name for platform in payload.platforms]
76+
),
7577
),
7678
)
7779
)
@@ -105,7 +107,14 @@ async def create_product(
105107
)
106108
task_results = await asyncio.gather(*repo_tasks)
107109

108-
for repo_name, repo_url, arch, pulp_href, export_path, is_debug in task_results:
110+
for (
111+
repo_name,
112+
repo_url,
113+
arch,
114+
pulp_href,
115+
export_path,
116+
is_debug,
117+
) in task_results:
109118
repo = models.Repository(
110119
name=repo_name,
111120
url=repo_url,
@@ -180,13 +189,21 @@ def generate_query(count=False):
180189
selectinload(models.Product.owner),
181190
selectinload(models.Product.platforms),
182191
selectinload(models.Product.repositories),
183-
selectinload(models.Product.roles).selectinload(models.UserRole.actions),
184-
selectinload(models.Product.team).selectinload(models.Team.owner),
192+
selectinload(models.Product.roles).selectinload(
193+
models.UserRole.actions
194+
),
195+
selectinload(models.Product.team).selectinload(
196+
models.Team.owner
197+
),
185198
selectinload(models.Product.team)
186199
.selectinload(models.Team.roles)
187200
.selectinload(models.UserRole.actions),
188-
selectinload(models.Product.team).selectinload(models.Team.members),
189-
selectinload(models.Product.team).selectinload(models.Team.products),
201+
selectinload(models.Product.team).selectinload(
202+
models.Team.members
203+
),
204+
selectinload(models.Product.team).selectinload(
205+
models.Team.products
206+
),
190207
)
191208
)
192209
if count:
@@ -205,7 +222,9 @@ def generate_query(count=False):
205222
if page_number:
206223
return {
207224
'products': (await db.execute(generate_query())).scalars().all(),
208-
'total_products': (await db.execute(generate_query(count=True))).scalar(),
225+
'total_products': (
226+
await db.execute(generate_query(count=True))
227+
).scalar(),
209228
'current_page': page_number,
210229
}
211230
if product_id or product_name:
@@ -227,7 +246,9 @@ async def remove_product(
227246
db_product = await get_products(db, product_id=product_id)
228247
db_user = await get_user(db, user_id=user_id)
229248
if not can_perform(db_product, db_user, actions.DeleteProduct.name):
230-
raise PermissionDenied(f"User has no permissions to delete the product {db_product.name}")
249+
raise PermissionDenied(
250+
f"User has no permissions to delete the product {db_product.name}"
251+
)
231252
if not db_product:
232253
raise DataNotFoundError(f"Product={product_id} doesn't exist")
233254
active_builds_by_team_id = (
@@ -266,7 +287,8 @@ async def remove_product(
266287
# some repos from db can be absent in pulp
267288
# in case if you reset pulp db, but didn't reset non-pulp db
268289
if all(
269-
product_repo.name != product_distro['name'] for product_distro in all_product_distros
290+
product_repo.name != product_distro['name']
291+
for product_distro in all_product_distros
270292
):
271293
continue
272294
delete_tasks.append(pulp_client.delete_by_href(product_repo.pulp_href))
@@ -302,8 +324,12 @@ async def modify_product(
302324
)
303325
.options(
304326
selectinload(models.Build.repos),
305-
selectinload(models.Build.tasks).selectinload(models.BuildTask.rpm_modules),
306-
selectinload(models.Build.tasks).selectinload(models.BuildTask.platform),
327+
selectinload(models.Build.tasks).selectinload(
328+
models.BuildTask.rpm_modules
329+
),
330+
selectinload(models.Build.tasks).selectinload(
331+
models.BuildTask.platform
332+
),
307333
),
308334
)
309335

@@ -314,17 +340,19 @@ async def modify_product(
314340
)
315341
.options(
316342
selectinload(models.Build.repos),
317-
selectinload(models.Build.tasks).selectinload(models.BuildTask.rpm_modules),
318-
selectinload(models.Build.tasks).selectinload(models.BuildTask.platform),
343+
selectinload(models.Build.tasks).selectinload(
344+
models.BuildTask.rpm_modules
345+
),
346+
selectinload(models.Build.tasks).selectinload(
347+
models.BuildTask.platform
348+
),
319349
),
320350
)
321351
db_build = db_build.scalars().first()
322352

323353
if modification == 'add':
324354
if db_build in db_product.builds:
325-
error_msg = (
326-
f"Can't add build {build_id} to {product} as it's already part of the product"
327-
)
355+
error_msg = f"Can't add build {build_id} to {product} as it's already part of the product"
328356
raise ProductError(error_msg)
329357
if modification == 'remove':
330358
if db_build not in db_product.builds:
@@ -339,18 +367,24 @@ async def modify_product(
339367
perform_product_modification.send(db_build.id, db_product.id, modification)
340368

341369

342-
async def get_repo_product(session: AsyncSession, repository: str) -> Optional[Product]:
370+
async def get_repo_product(
371+
session: AsyncSession, repository: str
372+
) -> Optional[Product]:
343373
product_relationships = (
344374
selectinload(Product.owner),
345375
selectinload(Product.roles).selectinload(UserRole.actions),
346-
selectinload(Product.team).selectinload(Team.roles).selectinload(UserRole.actions),
376+
selectinload(Product.team)
377+
.selectinload(Team.roles)
378+
.selectinload(UserRole.actions),
347379
)
348380
if repository.endswith("br"):
349381
result = (
350382
(
351383
await session.execute(
352384
select(Build)
353-
.filter(Build.repos.any(Repository.name.ilike(f'%{repository}')))
385+
.filter(
386+
Build.repos.any(Repository.name.ilike(f'%{repository}'))
387+
)
354388
.options(
355389
joinedload(Build.team)
356390
.joinedload(Team.products)

alws/utils/copr.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ async def create_product_repo(
104104
create_publication=True,
105105
base_path_start='copr',
106106
)
107-
export_path = f"{product_name}/{platform_name}/{'debug/' if is_debug else ''}{arch}/"
107+
export_path = (
108+
f"{product_name}/{platform_name}/{'debug/' if is_debug else ''}{arch}/"
109+
)
108110
return repo_name, repo_url, arch, repo_href, export_path, is_debug
109111

110112

alws/utils/exporter.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ async def fs_export_repository(
1515
repository_ids: List[int],
1616
session: AsyncSession,
1717
):
18-
export_task = await repo_exporter.create_pulp_exporters_to_fs(session, repository_ids)
19-
export_data = await repo_exporter.execute_pulp_exporters_to_fs(session, export_task)
18+
export_task = await repo_exporter.create_pulp_exporters_to_fs(
19+
session,
20+
repository_ids,
21+
)
22+
export_data = await repo_exporter.execute_pulp_exporters_to_fs(
23+
session,
24+
export_task,
25+
)
2026
export_paths = list(export_data.keys())
2127
for repo_elem, repo_data in export_data.items():
2228
repo_url = urllib.parse.urljoin(repo_data, 'repodata/')

alws/utils/pulp_client.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ async def _upload_local_file(
368368
with open(file_path, "rb") as f:
369369
for i in range(chunks):
370370
chunk = io.BytesIO(f.read(chunk_size))
371-
chunk.name = (
372-
f'{file_path.strip("/").replace("/", "_")}_{i}'
373-
)
371+
chunk.name = f'{file_path.strip("/").replace("/", "_")}_{i}'
374372
payload = {"file": chunk}
375373
if chunk_size >= file_size:
376374
stop = file_size - 1
@@ -386,9 +384,7 @@ async def _upload_local_file(
386384
)
387385
start += chunk_size
388386
except Exception:
389-
logging.exception(
390-
"Exception during the file upload", exc_info=True
391-
)
387+
logging.exception("Exception during the file upload", exc_info=True)
392388
await self.request("DELETE", upload_href, raw=True)
393389
else:
394390
task = await self.request(
@@ -1053,7 +1049,9 @@ async def request(
10531049
return response_json
10541050

10551051

1056-
def get_pulp_client(semaphore: Optional[asyncio.Semaphore] = None) -> PulpClient:
1052+
def get_pulp_client(
1053+
semaphore: Optional[asyncio.Semaphore] = None,
1054+
) -> PulpClient:
10571055
return PulpClient(
10581056
host=settings.pulp_host,
10591057
username=settings.pulp_user,

scripts/add_export_paths_to_product_repos.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ def main():
1919
session.execute(
2020
select(Product)
2121
.where(Product.is_community.is_(True))
22-
.options(joinedload(Product.repositories), joinedload(Product.platforms))
22+
.options(
23+
joinedload(Product.repositories),
24+
joinedload(Product.platforms),
25+
)
2326
)
2427
.scalars()
2528
.unique()
2629
.all()
2730
):
2831
if not product.repositories:
2932
continue
30-
platform_names = '|'.join((platform.name for platform in product.platforms))
33+
platform_names = '|'.join(
34+
(platform.name for platform in product.platforms)
35+
)
3136
platform_pattern = re.compile(
3237
rf'-({platform_names})-(\w+)(-debug|)-dr$',
3338
flags=re.IGNORECASE,
@@ -39,9 +44,7 @@ def main():
3944
if not regex_result:
4045
continue
4146
platform, *_ = regex_result.groups()
42-
repo.export_path = (
43-
f"{product.name}/{platform}/{'debug/' if repo.debug else ''}{repo.arch}/"
44-
)
47+
repo.export_path = f"{product.name}/{platform}/{'debug/' if repo.debug else ''}{repo.arch}/"
4548

4649

4750
if __name__ == '__main__':

scripts/exporters/base_exporter.py

+29-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
self,
2323
repodata_cache_dir: str,
2424
logger_name: str = '',
25-
log_file_path: Path = Path('/tmp/exporter.log'),
25+
log_file_path: Path = Path('/srv/exporter.log'),
2626
verbose: bool = False,
2727
export_method: Literal['write', 'hardlink', 'symlink'] = 'hardlink',
2828
export_path: str = settings.pulp_export_path,
@@ -32,7 +32,9 @@ def __init__(
3232
self.export_path = export_path
3333
self.createrepo_c = local["createrepo_c"]
3434

35-
self.repodata_cache_dir = Path(repodata_cache_dir).expanduser().absolute()
35+
self.repodata_cache_dir = (
36+
Path(repodata_cache_dir).expanduser().absolute()
37+
)
3638
self.checksums_cache_dir = self.repodata_cache_dir.joinpath('checksums')
3739
for dir_path in (self.repodata_cache_dir, self.checksums_cache_dir):
3840
if dir_path.exists():
@@ -52,7 +54,9 @@ def __init__(
5254
)
5355

5456
def regenerate_repo_metadata(self, repo_path: str):
55-
partial_path = re.sub(str(settings.pulp_export_path), "", str(repo_path)).strip("/")
57+
partial_path = re.sub(
58+
str(settings.pulp_export_path), "", str(repo_path)
59+
).strip("/")
5660
repodata_path = Path(repo_path, "repodata")
5761
repo_repodata_cache = self.repodata_cache_dir.joinpath(partial_path)
5862
cache_repodata_dir = repo_repodata_cache.joinpath("repodata")
@@ -86,20 +90,26 @@ async def create_filesystem_exporters(
8690
get_publications: bool = False,
8791
):
8892
async def get_exporter_data(repository: Repository) -> Tuple[str, dict]:
89-
export_path = str(Path(self.export_path, repository.export_path, "Packages"))
93+
export_path = str(
94+
Path(self.export_path, repository.export_path, "Packages")
95+
)
9096
exporter_name = (
9197
f"{repository.name}-{repository.arch}-debug"
9298
if repository.debug
9399
else f"{repository.name}-{repository.arch}"
94100
)
95-
fs_exporter_href = await self.pulp_client.create_filesystem_exporter(
96-
exporter_name,
97-
export_path,
98-
export_method=self.export_method,
101+
fs_exporter_href = (
102+
await self.pulp_client.create_filesystem_exporter(
103+
exporter_name,
104+
export_path,
105+
export_method=self.export_method,
106+
)
99107
)
100108

101-
repo_latest_version = await self.pulp_client.get_repo_latest_version(
102-
repository.pulp_href
109+
repo_latest_version = (
110+
await self.pulp_client.get_repo_latest_version(
111+
repository.pulp_href
112+
)
103113
)
104114
if not repo_latest_version:
105115
raise ValueError('cannot find latest repo version')
@@ -126,7 +136,9 @@ async def get_exporter_data(repository: Repository) -> Tuple[str, dict]:
126136
result = await session.execute(query)
127137
repositories = list(result.scalars().all())
128138

129-
results = await asyncio.gather(*(get_exporter_data(repo) for repo in repositories))
139+
results = await asyncio.gather(
140+
*(get_exporter_data(repo) for repo in repositories)
141+
)
130142

131143
return list(dict(results).values())
132144

@@ -148,7 +160,9 @@ async def _export_repository(self, exporter: dict) -> Optional[str]:
148160
href = exporter["exporter_href"]
149161
repository_version = exporter["repo_latest_version"]
150162
try:
151-
await self.pulp_client.export_to_filesystem(href, repository_version)
163+
await self.pulp_client.export_to_filesystem(
164+
href, repository_version
165+
)
152166
except Exception:
153167
self.logger.exception(
154168
"Cannot export repository via %s",
@@ -178,5 +192,7 @@ async def _export_repository(self, exporter: dict) -> Optional[str]:
178192

179193
async def export_repositories(self, repo_ids: List[int]) -> List[str]:
180194
exporters = await self.create_filesystem_exporters(repo_ids)
181-
results = await asyncio.gather(*(self._export_repository(e) for e in exporters))
195+
results = await asyncio.gather(
196+
*(self._export_repository(e) for e in exporters)
197+
)
182198
return [path for path in results if path]

0 commit comments

Comments
 (0)