Files
edx-platform/lms/djangoapps/dashboard/management/commands/git_add_course.py
edX requirements bot f33f12bbea BOM-2358 : Pyupgrade in dashboard, debug, discussion apps (#26529)
* Python code cleanup by the cleanup-python-code Jenkins job.

This pull request was generated by the cleanup-python-code Jenkins job, which ran
```
cd lms/djangoapps/dashboard; find . -type f -name '*.py' | while read fname; do sed -i 's/  # lint-amnesty, pylint: disable=super-with-arguments//; s/  # lint-amnesty, pylint: disable=import-error, wrong-import-order//; s/  # lint-amnesty, pylint: disable=wrong-import-order//' "$fname"; done; find . -type f -name '*.py' | while read fname; do pyupgrade --exit-zero-even-if-changed --py3-plus --py36-plus --py38-plus "$fname"; done; isort --recursive .
```

The following packages were installed:
`pyupgrade,isort`

* feedback done

Co-authored-by: Zulqarnain <muhammad.zulqarnain@arbisoft.com>
2021-02-22 15:42:21 +05:00

55 lines
2.0 KiB
Python

"""
Script for importing courseware from git/xml into a mongo modulestore
"""
import logging
from django.core.management.base import BaseCommand, CommandError
from django.utils.translation import ugettext as _
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.xml import XMLModuleStore
from lms.djangoapps.dashboard import git_import
log = logging.getLogger(__name__)
class Command(BaseCommand):
"""
Pull a git repo and import into the mongo based content database.
"""
# Translators: A git repository is a place to store a grouping of
# versioned files. A branch is a sub grouping of a repository that
# has a specific version of the repository. A modulestore is the database used
# to store the courses for use on the Web site.
help = ('Usage: '
'git_add_course repository_url [directory to check out into] [repository_branch] '
'\n{}'.format(_('Import the specified git repository and optional branch into the '
'modulestore and optionally specified directory.')))
def add_arguments(self, parser):
# Positional arguments
parser.add_argument('repository_url')
parser.add_argument('--directory_path', action='store')
parser.add_argument('--repository_branch', action='store')
def handle(self, *args, **options):
"""Check inputs and run the command"""
if isinstance(modulestore, XMLModuleStore):
raise CommandError('This script requires a mongo module store')
rdir_arg = None
branch = None
if options['directory_path']:
rdir_arg = options['directory_path']
if options['repository_branch']:
branch = options['repository_branch']
try:
git_import.add_repo(options['repository_url'], rdir_arg, branch)
except git_import.GitImportError as ex:
raise CommandError(str(ex)) # lint-amnesty, pylint: disable=raise-missing-from