Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processor resource discovery #559

Merged
merged 74 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
2257876
utils: implement resource lookup logic
kba Aug 10, 2020
a7b8001
utils: list_all_resources to list all processor resources
kba Aug 10, 2020
7e362d7
ocrd_utils.constants: XDG_CACHE_HOME
kba Aug 10, 2020
78e84a2
list_all_resources: also look in XDG_CACHE_HOME
kba Aug 10, 2020
5c75f40
Processor: implement resolve_resource and list_all_resources
kba Aug 10, 2020
bb63210
resolve_resource: also look in XDG_CACHE_HOME
kba Aug 10, 2020
297a0f3
Processor: fix signature for list_resource_candidates
kba Aug 10, 2020
c999229
initial test of list_resource_candidates
kba Aug 25, 2020
479cedd
test_os: not all test environments have VIRTUAL_ENV set
kba Oct 13, 2020
247bf4d
Merge branch 'master' into resolve-files
kba Oct 19, 2020
8e0b595
Merge branch 'master' into resolve-files
kba Oct 27, 2020
0d97c2d
wip
kba Oct 27, 2020
a54b5bf
Merge branch 'master' into resolve-files
kba Dec 11, 2020
6e76653
fixes merge error {f,}chmod
kba Dec 11, 2020
afcd117
run non-logging unit tests with standard $HOME
kba Dec 15, 2020
a3226b1
implement -C/-L cmdline flags
kba Dec 16, 2020
c2e0460
schema for resource list
kba Dec 21, 2020
5a6ccf3
implement foundation of ocrd resmgr
kba Dec 21, 2020
128f6b7
ocrd resmgr list-{installed,available} same output
kba Dec 21, 2020
0f42da6
resmgr: basic downloading of urls of files
kba Dec 22, 2020
b63b4d8
resmgr: support parameter_usage different from resource name
kba Dec 22, 2020
3f0eeac
add more models to resource_list.yml
kba Dec 22, 2020
6e6e424
resmgr: simplify resource typing
kba Dec 22, 2020
5843e1b
resmgr: support tarball downloads
kba Dec 22, 2020
0edac70
search for resources only on top-level
kba Dec 22, 2020
f96ce5e
use resmgr in Processor.resolve_resource
kba Dec 22, 2020
fa90f1b
simplify Processor.resolve_resource, delegate to resmgr as much as po…
kba Dec 22, 2020
89f77f0
resmgr: add anybaseocr resources
kba Dec 23, 2020
18009a7
resmgr download: show progressbar, add size to resource list
kba Dec 23, 2020
2df4c22
fix resmgr test
kba Dec 23, 2020
e8d0e0f
resmgr download: * to download all resources for this model
kba Dec 23, 2020
1fd35b9
:package: pre-release 2.22.0b1
kba Dec 28, 2020
849de10
new PAGE XML user method get_AllTextLine
kba Dec 30, 2020
bf47a07
update assets
kba Dec 30, 2020
db36dd3
kraken resources
kba Dec 30, 2020
a571b82
:package: pre-release 2.22.0b2
kba Dec 30, 2020
3aa60a8
reslist: use name w/o slash
kba Dec 30, 2020
4bf12fb
:package: pre-release v2.22.0b3
kba Dec 31, 2020
2c26eb0
Update ocrd/ocrd/processor/base.py
kba Jan 4, 2021
02e6415
rename PAGE method get_AllTextLine{,s}
kba Jan 4, 2021
4def1d9
OcrdPage.get_AllTextLines: support region_order, stub for textline_order
kba Jan 4, 2021
7911603
ocrd resmgr list-installed: look in fs for candidates
kba Jan 5, 2021
54a214a
resource_list.yml: typo: ocrd{,-cis}-ocropy-recognize
kba Jan 5, 2021
e33346b
resmgr list-installed: create stub in user resource list for unregist…
kba Jan 5, 2021
3ee66ce
resmgr: use last URL segment as the resource name
kba Jan 5, 2021
b21d462
resmgr: unquote URL encoded path
kba Jan 5, 2021
d8d97af
resmgr: use GET instead of HEAD for content-length
kba Jan 6, 2021
509200c
resmgr: support "download" (=copying) of local files
kba Jan 7, 2021
cbbc09a
resmgr, introduce intermediary "ocrd-resource" dir
kba Jan 12, 2021
7b1b6c9
default to VIRTUAL_ENV sharedir
kba Jan 12, 2021
565ba38
resmgr: save stub on download
kba Jan 12, 2021
012e49e
get_AllTextLines: implement textlineOrder
bertsky Jan 12, 2021
199b430
resmgr: ocrd-resources also for list_resource_candidates
kba Jan 12, 2021
8349807
resmgr: add @stweil's ONB model to list
kba Jan 14, 2021
7840b5b
resmgr: when wildcard downloading, omit ??? user entries
kba Jan 18, 2021
5038005
add a config file $XDG_CONFIG_HOME/ocrd.yml
kba Jan 19, 2021
2ab2151
ocrd resmgr: use resource_location from config for default
kba Jan 19, 2021
4687886
config: merge with default config for updated config
kba Jan 19, 2021
032929e
move config file to $XDG_CONFIG_HOME/ocrd/config.yml for consistency
kba Jan 19, 2021
c6a53b0
resource manager: methods to resolve resource dirs
kba Jan 19, 2021
a741a72
Merge branch 'master' into resolve-files
kba Jan 20, 2021
53a591d
:package: v2.22.0b4
kba Jan 20, 2021
a05ecf4
fix ocrd_config test
kba Jan 20, 2021
61a8845
config: mkdir -p $(basename)
kba Jan 20, 2021
fd8ca26
:bug: resmgr: virtualenv location was missing "share"
kba Jan 21, 2021
a3cff9e
resmgr: show shorthand location in list-installed
kba Jan 21, 2021
9280ef4
remove virtualenv, introduce /usr/local/share
kba Jan 22, 2021
9cb058a
:fire: remove configuration file
kba Jan 22, 2021
7e26a07
resmgr: lookup in XDG_DATA_HOME and absolute path only
kba Jan 22, 2021
22fb2c6
resmgr download: be stricter about uninstalled processors
kba Jan 25, 2021
2b3cb64
resmgr download "*"
kba Jan 25, 2021
ac74c3d
Update ocrd/ocrd/resource_manager.py
kba Jan 25, 2021
134a0c1
Update ocrd/ocrd/resource_manager.py
kba Jan 25, 2021
a5858ec
allow "from ocrd import OcrdResourceManager"
kba Jan 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ocrd/ocrd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from ocrd_validators import *
from ocrd.workspace import Workspace
from ocrd.workspace_backup import WorkspaceBackupManager
from ocrd.resource_manager import OcrdResourceManager
31 changes: 24 additions & 7 deletions ocrd/ocrd/cli/resmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from os import getcwd
from os.path import join
from pathlib import Path
import requests
from distutils.spawn import find_executable as which
bertsky marked this conversation as resolved.
Show resolved Hide resolved

import requests
import click

from ocrd_utils import (
Expand Down Expand Up @@ -56,11 +57,12 @@ def list_installed(executable=None):

@resmgr_cli.command('download')
@click.option('-n', '--any-url', help='Allow downloading/copying unregistered resources', is_flag=True)
@click.option('-a', '--allow-uninstalled', help="Allow installing resources for uninstalled processors", is_flag=True)
@click.option('-o', '--overwrite', help='Overwrite existing resources', is_flag=True)
@click.option('-l', '--location', help='Where to store resources', type=click.Choice(RESOURCE_LOCATIONS), default='data', show_default=True)
@click.argument('executable', required=True)
@click.argument('url_or_name', required=True)
def download(any_url, overwrite, location, executable, url_or_name):
@click.argument('url_or_name', required=False)
def download(any_url, allow_uninstalled, overwrite, location, executable, url_or_name):
"""
Download resource URL_OR_NAME for processor EXECUTABLE.

Expand All @@ -73,10 +75,22 @@ def download(any_url, overwrite, location, executable, url_or_name):
log = getLogger('ocrd.cli.resmgr')
resmgr = OcrdResourceManager()
basedir = resmgr.location_to_resource_dir(location)
is_url = url_or_name.startswith('https://') or url_or_name.startswith('http://')
is_filename = Path(url_or_name).exists()
if executable != '*' and not url_or_name:
log.error("Unless EXECUTABLE ('%s') is the '*' wildcard, URL_OR_NAME is required" % executable)
sys.exit(1)
elif executable == '*':
executable = None
is_url = (url_or_name.startswith('https://') or url_or_name.startswith('http://')) if url_or_name else False
is_filename = Path(url_or_name).exists() if url_or_name else False
if executable and not which(executable):
if not allow_uninstalled:
log.error("Executable %s is not installed. Is there a typo in the executable? " \
"To install resources for uninstalled processor, use the -a/--allow-uninstalled flag" % executable)
sys.exit(1)
else:
log.warning("Executable %s is not installed but -a/--allow-uninstalled was given, so proceeding" % executable)
find_kwargs = {'executable': executable}
if url_or_name != '*':
if url_or_name and url_or_name != '*':
find_kwargs['url' if is_url else 'name'] = url_or_name
reslist = resmgr.find_resources(**find_kwargs)
if not reslist:
Expand All @@ -103,7 +117,10 @@ def download(any_url, overwrite, location, executable, url_or_name):
else:
sys.exit(1)
else:
for _, resdict in reslist:
for executable, resdict in reslist:
if not allow_uninstalled and not which(executable):
log.info("Skipping installing resources for %s as it is not installed. (Use -a/--allow-uninstalled to force)")
continue
if resdict['url'] == '???':
log.info("Cannot download user resource %s" % (resdict['name'])),
continue
Expand Down
5 changes: 4 additions & 1 deletion ocrd/ocrd/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def list_installed(self, executable=None):
# resources we know about
all_executables = list(self.database.keys())
# resources in the file system
parent_dirs = [join(x, 'ocrd-resources') for x in [XDG_DATA_HOME, '/usr/local/share']]
parent_dirs = [join(x, 'ocrd-resources') for x in [XDG_DATA_HOME, '/usr/local/share', getcwd()]]
for parent_dir in parent_dirs:
if Path(parent_dir).exists():
all_executables += [x for x in listdir(parent_dir) if x.startswith('ocrd-')]
Expand Down Expand Up @@ -131,6 +131,9 @@ def find_resources(self, executable=None, name=None, url=None, database=None):
ret.append((executable, resdict))
return ret

kba marked this conversation as resolved.
Show resolved Hide resolved
@property
def default_resource_dir(self):
return self.location_to_resource_dir('data')
def location_to_resource_dir(self, location):
return '/usr/local/share/ocrd-resources' if location == 'system' else \
join(XDG_DATA_HOME, 'ocrd-resources') if location == 'data' else \
Expand Down