Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
grouprise
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lix Luthor
grouprise
Commits
34700549
Commit
34700549
authored
4 years ago
by
Lars Kruse
Browse files
Options
Downloads
Patches
Plain Diff
restore_tags: fix style issues by applying "black" formatting
parent
370ad05e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
grouprise/features/tags/management/commands/restore_tags.py
+37
-20
37 additions, 20 deletions
grouprise/features/tags/management/commands/restore_tags.py
with
37 additions
and
20 deletions
grouprise/features/tags/management/commands/restore_tags.py
+
37
−
20
View file @
34700549
...
...
@@ -9,13 +9,15 @@ from grouprise.features.content.models import Version
class
Command
(
BaseCommand
):
TAGS_PATTERN
=
rb
'
COPY public\.tags_tag.*?;\s*(.*?)\\\.
'
LINKS_PATTERN
=
rb
'
COPY public\.tags_tagged.*?;\s*(.*?)\\\.
'
TAGS_PATTERN
=
rb
"
COPY public\.tags_tag.*?;\s*(.*?)\\\.
"
LINKS_PATTERN
=
rb
"
COPY public\.tags_tagged.*?;\s*(.*?)\\\.
"
help
=
'
Restores tags from a grouprise 2.x database dump.
'
help
=
"
Restores tags from a grouprise 2.x database dump.
"
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
dump_file
'
,
help
=
'
filename of version 2.x SQL database dump
'
)
parser
.
add_argument
(
"
dump_file
"
,
help
=
"
filename of version 2.x SQL database dump
"
)
def
handle
(
self
,
*
args
,
**
options
):
def
get_data
(
pattern_str
):
...
...
@@ -23,37 +25,52 @@ class Command(BaseCommand):
match
=
pattern
.
search
(
mm
)
if
match
:
for
dataset
in
match
[
1
].
splitlines
():
yield
dataset
.
decode
().
split
(
sep
=
'
\t
'
)
yield
dataset
.
decode
().
split
(
sep
=
"
\t
"
)
else
:
raise
CommandError
(
'
Dump file does not contain tag data
'
)
raise
CommandError
(
"
Dump file does not contain tag data
"
)
dump_file
=
options
.
get
(
'
dump_file
'
)
dump_file
=
options
.
get
(
"
dump_file
"
)
with
open
(
dump_file
,
'
r
'
)
as
f
:
with
open
(
dump_file
,
"
r
"
)
as
f
:
with
mmap
.
mmap
(
f
.
fileno
(),
0
,
access
=
mmap
.
ACCESS_READ
)
as
mm
:
tags
=
{
int
(
data
[
0
]):
{
'
name
'
:
data
[
1
],
'
slug
'
:
data
[
2
]}
for
data
in
get_data
(
self
.
TAGS_PATTERN
)}
links
=
[{
'
tagged
'
:
int
(
data
[
1
]),
'
tagged_type
'
:
int
(
data
[
2
]),
'
tag
'
:
int
(
data
[
3
])}
for
data
in
get_data
(
self
.
LINKS_PATTERN
)]
tags
=
{
int
(
data
[
0
]):
{
"
name
"
:
data
[
1
],
"
slug
"
:
data
[
2
]}
for
data
in
get_data
(
self
.
TAGS_PATTERN
)
}
links
=
[
{
"
tagged
"
:
int
(
data
[
1
]),
"
tagged_type
"
:
int
(
data
[
2
]),
"
tag
"
:
int
(
data
[
3
]),
}
for
data
in
get_data
(
self
.
LINKS_PATTERN
)
]
for
link
in
links
:
content_type
=
ContentType
.
objects
.
get_for_id
(
link
[
'
tagged_type
'
])
content_type
=
ContentType
.
objects
.
get_for_id
(
link
[
"
tagged_type
"
])
try
:
model
=
content_type
.
get_object_for_this_type
(
id
=
link
[
'
tagged
'
])
model
=
content_type
.
get_object_for_this_type
(
id
=
link
[
"
tagged
"
])
except
:
print
(
'
Warning: Tagged object does no longer exist (type {}, id {})
'
.
format
(
link
[
'
tagged_type
'
],
link
[
'
tagged
'
]))
print
(
"
Warning: Tagged object does no longer exist (type {}, id {})
"
.
format
(
link
[
"
tagged_type
"
],
link
[
"
tagged
"
]
)
)
continue
if
isinstance
(
model
,
Contribution
):
model
=
model
.
container
elif
isinstance
(
model
,
Version
):
model
=
model
.
content
if
hasattr
(
model
,
'
tags
'
):
tag_name
=
tags
[
link
[
'
tag
'
]][
'
name
'
]
if
hasattr
(
model
,
"
tags
"
):
tag_name
=
tags
[
link
[
"
tag
"
]][
"
name
"
]
if
len
(
tag_name
)
<=
100
:
model
.
tags
.
add
(
tag_name
)
else
:
print
(
'
Warning: Tag name is too long: {}
'
.
format
(
tag_name
))
print
(
"
Warning: Tag name is too long: {}
"
.
format
(
tag_name
))
else
:
print
(
'
Warning: Model of type {} is not taggable
'
.
format
(
model
.
__class__
.
__name__
))
print
(
"
Warning: Model of type {} is not taggable
"
.
format
(
model
.
__class__
.
__name__
)
)
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