Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
0b2b9fe2
Commit
0b2b9fe2
authored
9 years ago
by
E. Kolpakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added management command to manually reindex libraries
parent
bd8754b0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
cms/djangoapps/contentstore/management/commands/reindex_library.py
+75
-0
No files found.
cms/djangoapps/contentstore/management/commands/reindex_library.py
0 → 100644
View file @
0b2b9fe2
from
django.core.management
import
BaseCommand
,
CommandError
from
optparse
import
make_option
from
textwrap
import
dedent
from
contentstore.courseware_index
import
LibrarySearchIndexer
from
opaque_keys.edx.keys
import
CourseKey
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locator
import
LibraryLocator
from
.prompt
import
query_yes_no
from
xmodule.modulestore.django
import
modulestore
class
Command
(
BaseCommand
):
"""
Command to reindex content libraries (single, multiple or all available)
Examples:
./manage.py reindex_library lib1 lib2 - reindexes libraries with keys lib1 and lib2
./manage.py reindex_library --all - reindexes all available libraries
"""
help
=
dedent
(
__doc__
)
can_import_settings
=
True
args
=
"<library_id library_id ...>"
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--all'
,
action
=
'store_true'
,
dest
=
'all'
,
default
=
False
,
help
=
'Reindex all libraries'
),)
def
_parse_library_key
(
self
,
raw_value
):
""" Parses library key from string """
try
:
result
=
CourseKey
.
from_string
(
raw_value
)
except
InvalidKeyError
:
result
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
raw_value
)
if
not
isinstance
(
result
,
LibraryLocator
):
raise
CommandError
(
"Argument {0} is not a library key"
.
format
(
raw_value
))
return
result
def
handle
(
self
,
*
args
,
**
options
):
"""
By convention set by django developers, this method actually executes command's actions.
So, there could be no better docstring than emphasize this once again.
"""
if
len
(
args
)
==
0
and
not
options
.
get
(
'all'
,
False
):
raise
CommandError
(
"reindex_library requires one or more arguments: <library_id>"
)
store
=
modulestore
()
if
options
.
get
(
'all'
,
False
):
if
query_yes_no
(
"Reindexing all libraries might be a time consuming operation. Do you want to continue?"
,
default
=
"no"
):
library_keys
=
[
library
.
location
.
library_key
for
library
in
store
.
get_libraries
()]
else
:
return
else
:
library_keys
=
map
(
self
.
_parse_library_key
,
args
)
for
library_key
in
library_keys
:
LibrarySearchIndexer
.
do_library_reindex
(
store
,
library_key
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment