replace kwargs for more clearly

This commit is contained in:
Dmitry Afanasyev 2022-03-09 23:52:19 +03:00
parent 2410429e03
commit f392b4c879
4 changed files with 27 additions and 14 deletions

View File

@ -37,10 +37,10 @@ def create_parser() -> ArgumentParser:
parser.add_argument('-g', '--group', required=False, type=int,
help='Add group id it can be found under group name. Id must be integer')
parser.add_argument('-u', '--urls', nargs='+', help='Provide url or urls to mirror with it in format: '
'https://github.com/s3rius/FastAPI-template.git. '
'You can provide multiple urls separated by space. '
'Names will generate automatically from links')
parser.add_argument('-u', '--urls', nargs='+',
help='Provide url or urls to mirror with it in format: '
'https://github.com/s3rius/FastAPI-template.git. You can provide multiple urls '
'separated by space. Names will generate automatically from links')
parser.add_argument('-f', '--file', help='Add file with urls. Each url on new line. Can be combined with '
'--url option. Names will generate automatically from links')

View File

@ -92,13 +92,14 @@ class RepositoryCreator:
elif request.status_code != self.HTTP_200_OK:
logger.error(f'Error pull repository. Status code: {request.status_code}. Reason: {request.text}')
def create_repository_mirror(self, **kwargs):
def create_repository_mirror(self, github_url: str, group_id: int):
"""
Base action for one thread. Creates repository, add mirror url and triggers pull at te end
:param kwargs: Can contain github url to mirror of, gitlab group ID
:param github_url: Github url which will be mirrored
:param group_id: Gitlab group id which contains created repository
"""
repo_id = self.__create_new_project(kwargs['url'], kwargs['group_id'])
url = self.__add_pull_mirror(kwargs['url'], repo_id)
repo_id = self.__create_new_project(github_url, group_id)
url = self.__add_pull_mirror(github_url, repo_id)
if url:
self.__pull_github_repo(url, repo_id)

View File

@ -74,3 +74,17 @@ https://github.com/KristianOellegaard/django-health-check.git
https://github.com/wemake-services/django-split-settings.git
https://github.com/jazzband/django-constance.git
https://github.com/numpy/numpy.git
https://github.com/mher/flower.git
https://github.com/hynek/structlog.git
https://github.com/bradmontgomery/django-querycount.git
https://github.com/justinmayer/django-autoslug.git
https://github.com/SmileyChris/easy-thumbnails.git
https://github.com/jonasundderwolf/django-image-cropping.git
https://github.com/marshmallow-code/marshmallow.git
https://github.com/TvoroG/pytest-lazy-fixture.git
https://github.com/PyCQA/flake8.git
https://github.com/getsentry/responses.git
https://github.com/gotcha/ipdb.git
https://github.com/pypa/setuptools.git
https://github.com/jazzband/django-redis.git
https://github.com/sebleier/django-redis-cache.git

View File

@ -1,5 +1,5 @@
import sys
from threading import Thread, Semaphore
from threading import Thread
from core.argument_parser import create_parser
from core.repo_creator import RepositoryCreator
@ -33,15 +33,13 @@ def main():
if mirror_urls:
for url in set(mirror_urls): # github urls must be unique
thread = Thread(target=repository_creator.create_repository_mirror,
kwargs={'url': url, 'group_id': group_id, })
kwargs={'github_url': url, 'group_id': group_id, })
threads.append(thread)
for thread in threads:
with Semaphore(50):
thread.start()
threads_ready_statistic(threads) # add threads ready status to log output
else:
logger.info('You must provide at least one github url for mirror')
sys.exit(1)