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

Patch documentation #4903

Merged
merged 2 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 22 additions & 13 deletions lib/rucio/api/account_limit.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Copyright European Organization for Nuclear Research (CERN)
# -*- coding: utf-8 -*-
# Copyright 2014-2021 CERN
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# Authors:
# - Martin Barisits, <martin.barisits@cern.ch>, 2014
# - Cedric Serfon, <cedric.serfon@cern.ch>, 2015
# - Andrew Lister, <andrew.lister@stfc.ac.uk>, 2019
# - Hannes Hansen, <hannes.jakob.hansen@cern.ch>, 2019
# - Eli Chadwick, <eli.chadwick@stfc.ac.uk>, 2020
# - Patrick Austin, <patrick.austin@stfc.ac.uk>, 2020
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# PY3K COMPATIBLE
# Authors:
# - Martin Barisits <martin.barisits@cern.ch>, 2014
# - Cedric Serfon <cedric.serfon@cern.ch>, 2015
# - Hannes Hansen <hannes.jakob.hansen@cern.ch>, 2018-2019
# - Andrew Lister <andrew.lister@stfc.ac.uk>, 2019
# - Eli Chadwick <eli.chadwick@stfc.ac.uk>, 2020
# - Patrick Austin <patrick.austin@stfc.ac.uk>, 2020
# - David Población Criado <david.poblacion.criado@cern.ch>, 2021
# - Joel Dierkes <joel.dierkes@cern.ch>, 2021

import rucio.api.permission
import rucio.common.exception
Expand Down Expand Up @@ -219,7 +228,7 @@ def get_local_account_usage(account, rse, issuer, vo='def'):
:param issuer: The issuer account.
:param vo: The VO to act on.

:returns: List of dicts {'rse_id', 'bytes_used', 'files_used', 'bytes_limit'}
:returns: List of dicts {'rse_id', 'rse', 'bytes', 'files', 'bytes_limit', 'bytes_remaining'}
"""

rse_id = None
Expand Down Expand Up @@ -247,7 +256,7 @@ def get_global_account_usage(account, rse_expression, issuer, vo='def'):
:param issuer: The issuer account.
:param vo: The VO to act on.

:returns: List of dicts {'rse_id', 'bytes_used', 'files_used', 'bytes_limit'}
:returns: List of dicts {'rse_id', 'rse', 'bytes', 'files', 'bytes_limit', 'bytes_remaining'}
"""

kwargs = {'account': account, 'rse_expression': rse_expression}
Expand Down
10 changes: 6 additions & 4 deletions lib/rucio/core/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
# - Angelos Molfetas <Angelos.Molfetas@cern.ch>, 2012
# - Mario Lassnig <mario.lassnig@cern.ch>, 2012-2020
# - Vincent Garonne <vincent.garonne@cern.ch>, 2012-2015
# - Martin Barisits <martin.barisits@cern.ch>, 2014-2021
# - Martin Barisits <martin.barisits@cern.ch>, 2014-2019
# - Cedric Serfon <cedric.serfon@cern.ch>, 2014-2019
# - Joaquín Bogado <jbogado@linti.unlp.edu.ar>, 2015
# - Hannes Hansen <hannes.jakob.hansen@cern.ch>, 2018-2019
# - Andrew Lister <andrew.lister@stfc.ac.uk>, 2019
# - Patrick Austin <patrick.austin@stfc.ac.uk>, 2020
# - Benedikt Ziemons <benedikt.ziemons@cern.ch>, 2020
# - David Población Criado <david.poblacion.criado@cern.ch>, 2021
# - Joel Dierkes <joel.dierkes@cern.ch>, 2021

from datetime import datetime
from enum import Enum
Expand Down Expand Up @@ -309,7 +311,7 @@ def get_usage(rse_id, account, session=None):
:param rse_id: The id of the RSE.
:param account: The account name.
:param session: The database session in use.
:returns: A dictionary with total and bytes.
:returns: A dictionary {'bytes', 'files', 'updated_at'}
"""

try:
Expand All @@ -327,7 +329,7 @@ def get_all_rse_usages_per_account(account, session=None):
:param rse_id: The id of the RSE.
:param account: The account name.
:param session: The database session in use.
:returns: A dictionary with total and bytes.
:returns: List of dicts with :py:class:`models.AccountUsage` items
"""

try:
Expand All @@ -344,7 +346,7 @@ def get_usage_history(rse_id, account, session=None):
:param rse_id: The id of the RSE.
:param account: The account name.
:param session: The database session in use.
:returns: A dictionary with total and bytes.
:returns: A dictionary {'bytes', 'files', 'updated_at'}
"""

result = []
Expand Down
25 changes: 13 additions & 12 deletions lib/rucio/core/account_limit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2013-2018 CERN for the benefit of the ATLAS collaboration.
# -*- coding: utf-8 -*-
# Copyright 2014-2021 CERN
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,15 +14,15 @@
# limitations under the License.
#
# Authors:
# - Martin Barisits, <martin.barisits@cern.ch>, 2013-2018
# - Cedric Serfon, <cedric.serfon@cern.ch>, 2015
# - Vincent Garonne, <vincent.garonne@cern.ch>, 2015
# - Hannes Hansen, <hannes.jakob.hansen@cern.ch>, 2018-2019
# - Andrew Lister, <andrew.lister@stfc.ac.uk>, 2019
# - Patrick Austin, <patrick.austin@stfc.ac.uk>, 2020
# - Eli Chadwick, <eli.chadwick@stfc.ac.uk>, 2020
#
# PY3K COMPATIBLE
# - Martin Barisits <martin.barisits@cern.ch>, 2014-2018
# - Cedric Serfon <cedric.serfon@cern.ch>, 2015
# - Vincent Garonne <vincent.garonne@cern.ch>, 2015
# - Hannes Hansen <hannes.jakob.hansen@cern.ch>, 2018-2019
# - Andrew Lister <andrew.lister@stfc.ac.uk>, 2019
# - Patrick Austin <patrick.austin@stfc.ac.uk>, 2020
# - Eli Chadwick <eli.chadwick@stfc.ac.uk>, 2020
# - David Población Criado <david.poblacion.criado@cern.ch>, 2021
# - Joel Dierkes <joel.dierkes@cern.ch>, 2021

from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.sql import func
Expand Down Expand Up @@ -240,7 +241,7 @@ def get_local_account_usage(account, rse_id=None, session=None):
:param rse_id: The rse_id to read (If none, get all).
:param session: Database session in use.

:returns: List of dicts {'rse_id', 'bytes_used', 'files_used', 'bytes_limit'}
:returns: List of dicts {'rse_id', 'rse', 'bytes', 'files', 'bytes_limit', 'bytes_remaining'}
"""

if not rse_id:
Expand Down Expand Up @@ -271,7 +272,7 @@ def get_global_account_usage(account, rse_expression=None, session=None):
:param rse_expression: The RSE expression (If none, get all).
:param session: Database session in use.

:returns: List of dicts {'rse_id', 'bytes_used', 'files_used', 'bytes_limit'}
:returns: List of dicts {'rse_expression', 'bytes', 'files' 'bytes_limit', 'bytes_remaining'}
"""
result_list = []
if not rse_expression:
Expand Down
27 changes: 17 additions & 10 deletions tools/add_header
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# - Mario Lassnig <mario.lassnig@cern.ch>, 2021
# - Radu Carpa <radu.carpa@cern.ch>, 2021
# - David Población Criado <david.poblacion.criado@cern.ch>, 2021
# - Joel Dierkes <joel.dierkes@cern.ch>, 2021

"""
Utility script to generate header file
Expand Down Expand Up @@ -73,6 +74,7 @@ author_map = {
("rcarpa", "<2905943+rcarpa@users.noreply.github.com>"): ("Radu Carpa", "<radu.carpa@cern.ch>"),
("Dhruv Sondhi", "<66117751+DhruvSondhi@users.noreply.github.com>"): ("Dhruv Sondhi", "<dhruvsondhi05@gmail.com>"),
("David Población Criado", "<13998309+davidpob99@users.noreply.github.com>"): ("David Población Criado", "<david.poblacion.criado@cern.ch>"),
("Joel Dierkes", "<dierkesjoel@gmail.com>"): ("Joel Dierkes", "<joel.dierkes@cern.ch>"),
}


Expand All @@ -91,6 +93,7 @@ def main(arguments):
status, email = commands.getstatusoutput(cmd)
email = email.strip()
email = '<%s>' % email
exit_code = 0

for MyFile in arguments.MyFiles:
# Query log history
Expand Down Expand Up @@ -206,20 +209,21 @@ def main(arguments):
else:
header += '# - %(name)s %(mail)s, %(min)s-%(max)s\n' % authors[author]

try:
with open(MyFile, 'r') as original:
lines = original.readlines()
except UnicodeDecodeError as e:
raise RuntimeError('Cannot read file ' + str(MyFile)) from e

if arguments.check and header not in "".join(lines):
print("Header was modified in file", MyFile, file=sys.stderr)
exit_code = 1

if not arguments.dry_run:
if not arguments.in_place:
with open(MyFile, 'r') as original:
data = original.read()

with open(MyFile, 'w') as modified:
modified.write(header + '\n' + data)
modified.write(header + '\n' + "".join(lines))
else:
try:
with open(MyFile, 'r') as original:
lines = original.readlines()
except UnicodeDecodeError as e:
raise RuntimeError('Cannot read file ' + str(MyFile)) from e

with open(MyFile, 'w') as modified:
if not lines:
print('Empty lines at file', MyFile, file=sys.stderr)
Expand All @@ -242,6 +246,7 @@ def main(arguments):

else:
print(header)
exit(exit_code)


if __name__ == '__main__':
Expand All @@ -251,6 +256,8 @@ if __name__ == '__main__':
parser.add_argument('--in-place', '-i', action='store_true', default=False,
help='Edit files in-place (otherwise prepend).')
parser.add_argument('--dry-run', '-d', action='store_true', help='Dry run mode')
parser.add_argument('--check', '-c', action='store_true',
help='Checks if the script would change anything (non-zero exit code equals change).')
parser.add_argument(dest='MyFiles', action='store', nargs='+', default=None, help='The files')

main(parser.parse_args())