Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MJU-POPS
ckanext-archiver
Commits
7fde1b43
Commit
7fde1b43
authored
Jan 15, 2016
by
David Read
Browse files
Merge pull request #18 from mostrovoi/master
Fixing resource_group for ckan2.3+. Using same convention in all places
parents
d8729418
a6f9ea12
Changes
5
Show whitespace changes
Inline
Side-by-side
ckanext/archiver/bin/common.py
View file @
7fde1b43
import
os
import
ckan.plugins
as
p
def
load_config
(
config_filepath
):
import
paste.deploy
...
...
@@ -30,7 +30,7 @@ def get_resources(state='active', publisher_ref=None, resource_id=None,
from
ckan
import
model
resources
=
model
.
Session
.
query
(
model
.
Resource
)
\
.
filter_by
(
state
=
state
)
if
hasattr
(
model
,
'ResourceGroup
'
):
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99
'
):
# earlier CKANs had ResourceGroup
resources
=
resources
.
join
(
model
.
ResourceGroup
)
resources
=
resources
\
...
...
ckanext/archiver/commands.py
View file @
7fde1b43
...
...
@@ -5,6 +5,7 @@ import time
import
re
import
shutil
import
itertools
import
ckan.plugins
as
p
from
pylons
import
config
...
...
@@ -178,7 +179,7 @@ class Archiver(CkanCommand):
self
.
log
.
info
(
'Queue: %s'
,
self
.
options
.
queue
)
for
package
in
packages
:
if
hasattr
(
model
,
'ResourceGroup
'
):
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99
'
):
# earlier CKANs had ResourceGroup
pkg_resources
=
\
[
res
for
res
in
...
...
@@ -197,7 +198,10 @@ class Archiver(CkanCommand):
time
.
sleep
(
0.1
)
# to try to avoid Redis getting overloaded
for
resource
in
resources
:
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99'
):
package
=
resource
.
resource_group
.
package
else
:
package
=
resource
.
package
self
.
log
.
info
(
'Queuing resource %s/%s'
,
package
.
name
,
resource
.
id
)
lib
.
create_archiver_resource_task
(
resource
,
self
.
options
.
queue
)
time
.
sleep
(
0.05
)
# to try to avoid Redis getting overloaded
...
...
@@ -386,8 +390,14 @@ class Archiver(CkanCommand):
# check the package isn't deleted
# Need to refresh the resource's session
resource
=
model
.
Session
.
query
(
model
.
Resource
).
get
(
resource
.
id
)
if
resource
.
resource_group
and
resource
.
resource_group
.
package
:
if
resource
.
resource_group
.
package
.
state
==
model
.
State
.
DELETED
:
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99'
):
package
=
None
if
resource
.
resource_group
:
package
=
resource
.
resource_group
.
package
else
:
package
=
resource
.
package
if
package
and
package
.
state
==
model
.
State
.
DELETED
:
print
'Package is deleted'
continue
...
...
ckanext/archiver/lib.py
View file @
7fde1b43
import
os
import
logging
import
ckan.plugins
as
p
from
ckan
import
model
from
ckan.model.types
import
make_uuid
...
...
@@ -10,7 +11,7 @@ log = logging.getLogger(__name__)
def
create_archiver_resource_task
(
resource
,
queue
):
from
pylons
import
config
if
hasattr
(
model
,
'ResourceGroup
'
):
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99
'
):
# earlier CKANs had ResourceGroup
package
=
resource
.
resource_group
.
package
else
:
...
...
ckanext/archiver/model.py
View file @
7fde1b43
...
...
@@ -6,6 +6,8 @@ from sqlalchemy import types
from
sqlalchemy.ext.declarative
import
declarative_base
import
ckan.model
as
model
import
ckan.plugins
as
p
from
ckan.lib
import
dictization
log
=
__import__
(
'logging'
).
getLogger
(
__name__
)
...
...
@@ -145,7 +147,7 @@ class Archival(Base):
# Find the package_id for the resource.
dataset
=
model
.
Session
.
query
(
model
.
Package
)
if
hasattr
(
model
,
'ResourceGroup
'
):
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99
'
):
# earlier CKANs had ResourceGroup
dataset
=
dataset
.
join
(
model
.
ResourceGroup
)
dataset
=
dataset
\
...
...
ckanext/archiver/reports.py
View file @
7fde1b43
import
copy
import
ckan.model
as
model
from
ckan.lib.helpers
import
OrderedDict
import
ckan.plugins
as
p
from
ckan.lib.helpers
import
OrderedDict
from
ckanext.report
import
lib
def
broken_links
(
organization
,
include_sub_organizations
=
False
):
...
...
@@ -38,7 +39,7 @@ def broken_links_index(include_sub_organizations=False):
num_resources
=
model
.
Session
.
query
(
model
.
Package
)
\
.
filter_by
(
owner_org
=
org
.
id
)
\
.
filter_by
(
state
=
'active'
)
if
hasattr
(
model
,
'ResourceGroup
'
):
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99
'
):
num_resources
=
num_resources
.
join
(
model
.
ResourceGroup
)
num_resources
=
num_resources
\
.
join
(
model
.
Resource
)
\
...
...
@@ -199,7 +200,7 @@ def broken_links_for_organization(organization, include_sub_organizations=False)
.
count
()
num_resources
=
model
.
Session
.
query
(
model
.
Resource
)
\
.
filter_by
(
state
=
'active'
)
if
hasattr
(
model
,
'ResourceGroup
'
):
if
p
.
toolkit
.
check_ckan_version
(
max_version
=
'2.2.99
'
):
num_resources
=
num_resources
.
join
(
model
.
ResourceGroup
)
num_resources
=
num_resources
\
.
join
(
model
.
Package
)
\
...
...
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