Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9311478
swh-db-manager
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
swh-db-manager
View Options
#!/usr/bin/env python3
# Copyright (C) 2015 Stefano Zacchiroli <zack@upsilon.cc>,
# Antoine R. Dumont <antoine.romain.dumont@gmail.com>
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
argparse
import
configparser
import
logging
import
os
from
swh.manager
import
manage
# Default configuration file
DEFAULT_CONF_FILE
=
'~/.config/swh/db-manager.ini'
# default configuration (can be overriden by the DEFAULT_CONF_FILE)
DEFAULT_CONF
=
{
'log_dir'
:
'/tmp/swh-git-loader/log'
,
'db_url'
:
'dbname=swhgitloader'
,
}
def
parse_args
():
"""Parse the configuration for the cli.
"""
cli
=
argparse
.
ArgumentParser
(
description
=
'Parse git repository objects to load them into DB.'
)
cli
.
add_argument
(
'--verbose'
,
'-v'
,
action
=
'store_true'
,
help
=
'Verbosity level in log file.'
)
cli
.
add_argument
(
'--config'
,
'-c'
,
help
=
'configuration file path'
)
subcli
=
cli
.
add_subparsers
(
dest
=
'action'
)
subcli
.
add_parser
(
'initdb'
,
help
=
'initialize DB'
)
subcli
.
add_parser
(
'cleandb'
,
help
=
'clean DB'
)
args
=
cli
.
parse_args
()
if
not
args
.
action
:
cli
.
error
(
'no action given'
)
return
args
def
read_conf
(
args
):
"""Read the user's configuration file.
args contains the repo to parse.
"""
config
=
configparser
.
ConfigParser
(
defaults
=
DEFAULT_CONF
)
conf_file
=
args
.
config
or
DEFAULT_CONF_FILE
config
.
read
(
os
.
path
.
expanduser
(
conf_file
))
conf
=
config
.
_sections
[
'main'
]
# propagate CLI arguments to conf dictionary
conf
[
'action'
]
=
args
.
action
return
conf
if
__name__
==
'__main__'
:
args
=
parse_args
()
conf
=
read_conf
(
args
)
log_filename
=
os
.
path
.
join
(
conf
[
'log_dir'
],
'db-manager.log'
)
logging
.
basicConfig
(
filename
=
log_filename
,
level
=
logging
.
DEBUG
if
args
.
verbose
else
logging
.
INFO
)
manage
(
conf
[
'action'
],
conf
[
'db_url'
])
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Jul 3, 10:17 AM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3394658
Attached To
rDLDG Git loader
Event Timeline
Log In to Comment