Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
elasticsearch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
elasticsearch
Commits
3d097513f4dd
Commit
3d097513f4dd
authored
8 years ago
by
David Douard
Browse files
Options
Downloads
Patches
Plain Diff
[ccplugin] add a --loglevel cmd line option
parent
da3ef51e1b4e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ccplugin.py
+26
-16
26 additions, 16 deletions
ccplugin.py
with
26 additions
and
16 deletions
ccplugin.py
+
26
−
16
View file @
3d097513
...
...
@@ -11,8 +11,8 @@
from
elasticsearch.helpers
import
parallel_bulk
from
cubicweb.cwctl
import
CWCTL
from
cubicweb.
utils
import
admincnx
from
cubicweb.cwctl
import
CWCTL
,
init_cmdline_log_threshold
from
cubicweb.
cwconfig
import
CubicWebConfiguration
as
cwcfg
from
cubicweb.toolsutils
import
Command
from
cubes.elasticsearch.es
import
indexable_types
,
fulltext_indexable_rql
...
...
@@ -34,6 +34,7 @@
arguments
=
'
<instance id>
'
options
=
[
(
'
dry-run
'
,
{
'
type
'
:
'
yn
'
,
'
default
'
:
False
,
{
'
action
'
:
'
store_true
'
,
'
default
'
:
False
,
'
short
'
:
'
N
'
,
'
help
'
:
'
set to True if you want to skip the insertion in ES
'
}),
(
'
debug
'
,
...
...
@@ -38,8 +39,10 @@
'
help
'
:
'
set to True if you want to skip the insertion in ES
'
}),
(
'
debug
'
,
{
'
type
'
:
'
yn
'
,
'
default
'
:
False
,
'
help
'
:
(
'
set to True if you want to print
'
'
out debug info and progress
'
)}),
{
'
action
'
:
'
store_true
'
,
'
default
'
:
False
,
'
short
'
:
'
D
'
,
'
help
'
:
(
'
shortcut for --loglevel=debug
'
)}),
(
'
loglevel
'
,
{
'
short
'
:
'
l
'
,
'
type
'
:
'
choice
'
,
'
metavar
'
:
'
<log level>
'
,
'
default
'
:
None
,
'
choices
'
:
(
'
debug
'
,
'
info
'
,
'
warning
'
,
'
error
'
)}),
(
'
etypes
'
,
{
'
type
'
:
'
csv
'
,
'
default
'
:
''
,
'
help
'
:
'
only index given etypes [default:all indexable types]
'
}),
...
...
@@ -56,9 +59,14 @@
def
run
(
self
,
args
):
"""
run the command with its specific arguments
"""
appid
=
args
.
pop
(
0
)
with
admincnx
(
appid
)
as
cnx
:
if
self
[
'
debug
'
]:
self
[
'
loglevel
'
]
=
'
debug
'
config
=
cwcfg
.
config_for
(
appid
,
debugmode
=
self
[
'
loglevel
'
])
if
self
[
'
loglevel
'
]:
init_cmdline_log_threshold
(
config
,
self
[
'
loglevel
'
])
with
config
.
repository
().
internal_cnx
()
as
cnx
:
schema
=
cnx
.
vreg
.
schema
indexer
=
cnx
.
vreg
[
'
es
'
].
select
(
'
indexer
'
,
cnx
)
es
=
indexer
.
get_connection
()
indexer
.
create_index
()
if
self
.
config
.
index_name
:
...
...
@@ -60,8 +68,9 @@
schema
=
cnx
.
vreg
.
schema
indexer
=
cnx
.
vreg
[
'
es
'
].
select
(
'
indexer
'
,
cnx
)
es
=
indexer
.
get_connection
()
indexer
.
create_index
()
if
self
.
config
.
index_name
:
cnx
.
info
(
'
create ES index {}
'
.
format
(
self
.
config
.
index_name
))
indexer
.
create_index
(
index_name
=
self
.
config
.
index_name
)
if
es
:
if
self
.
config
.
etypes
:
...
...
@@ -70,8 +79,8 @@
etypes
=
indexable_types
(
schema
,
custom_skip_list
=
self
.
config
.
except_etypes
)
assert
self
.
config
.
except_etypes
not
in
etypes
if
self
.
config
.
debug
and
not
self
.
config
.
etypes
:
print
(
u
'
found indexable
_
types {}
'
.
format
(
if
not
self
.
config
.
etypes
:
cnx
.
debug
(
u
'
found indexable
types
:
{}
'
.
format
(
'
,
'
.
join
(
etypes
)))
for
_
in
parallel_bulk
(
es
,
self
.
bulk_actions
(
etypes
,
cnx
,
...
...
@@ -80,4 +89,5 @@
raise_on_error
=
False
,
raise_on_exception
=
False
):
pass
print
(
_
)
else
:
...
...
@@ -83,4 +93,3 @@
else
:
if
self
.
config
.
debug
:
print
(
u
'
no elasticsearch configuration found, skipping
'
)
cnx
.
info
(
u
'
no elasticsearch configuration found, skipping
'
)
...
...
@@ -86,6 +95,7 @@
def
bulk_actions
(
self
,
etypes
,
cnx
,
index_name
=
None
,
dry_run
=
False
):
def
bulk_actions
(
self
,
etypes
,
cnx
,
index_name
=
None
,
dry_run
=
False
):
if
index_name
is
None
:
index_name
=
cnx
.
vreg
.
config
[
'
index-name
'
]
for
etype
in
etypes
:
rql
=
fulltext_indexable_rql
(
etype
,
cnx
.
vreg
.
schema
)
rset
=
cnx
.
execute
(
rql
)
...
...
@@ -89,9 +99,9 @@
for
etype
in
etypes
:
rql
=
fulltext_indexable_rql
(
etype
,
cnx
.
vreg
.
schema
)
rset
=
cnx
.
execute
(
rql
)
if
self
.
config
.
debug
:
print
(
u
'
indexing {} {}
'
.
format
(
etype
,
len
(
rset
)
))
print
(
u
'
RQL : {}
'
.
format
(
rql
))
cnx
.
info
(
u
'
[{}] indexing {} {} entities
'
.
format
(
index_name
,
len
(
rset
),
etype
))
cnx
.
debug
(
u
'
RQL: {}
'
.
format
(
rql
))
for
entity
in
rset
.
entities
():
serializer
=
entity
.
cw_adapt_to
(
'
IFullTextIndexSerializable
'
)
json
=
serializer
.
serialize
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment