Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 6 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ ifndef PY
PY = 3
endif

FORMAT_ENFORCE_DIRS = state/
FORMAT_EXCLUDE_REGEX = '.*'
FORMAT_EXCLUDE_GLOB = '*'
FORMAT_LINE_LENGTH = 80

LINT_ENFORCE_DIRS = ./bin ./mig/lib ./sbin ./tests
LOCAL_PYTHON_BIN = './envhelp/lpython'

ifdef PYTHON_BIN
Expand Down Expand Up @@ -42,15 +38,10 @@ ifneq ($(MIG_ENV),'local')
endif
@make format-python

.PHONY:format-python
.PHONY: format-python
format-python:
@$(LOCAL_PYTHON_BIN) -m black $(FORMAT_ENFORCE_DIRS) \
--line-length=$(FORMAT_LINE_LENGTH) \
--exclude=$(FORMAT_EXCLUDE_REGEX)
@$(LOCAL_PYTHON_BIN) -m isort $(FORMAT_ENFORCE_DIRS) \
--profile=black \
--line-length=$(FORMAT_LINE_LENGTH) \
--skip-glob=$(FORMAT_EXCLUDE_GLOB)
@$(LOCAL_PYTHON_BIN) -m black $(LINT_ENFORCE_DIRS)
Comment thread
jonasbardino marked this conversation as resolved.
@$(LOCAL_PYTHON_BIN) -m isort $(LINT_ENFORCE_DIRS)

.PHONY: lint
lint:
Expand All @@ -62,15 +53,8 @@ endif

.PHONY: lint-python
lint-python:
@$(LOCAL_PYTHON_BIN) -m black $(FORMAT_ENFORCE_DIRS) \
--check \
--line-length=$(FORMAT_LINE_LENGTH) \
--exclude $(FORMAT_EXCLUDE_REGEX)
@$(LOCAL_PYTHON_BIN) -m isort $(FORMAT_ENFORCE_DIRS) \
--check-only \
--profile=black \
--line-length=$(FORMAT_LINE_LENGTH) \
--skip-glob=$(FORMAT_EXCLUDE_GLOB)
@$(LOCAL_PYTHON_BIN) -m black $(LINT_ENFORCE_DIRS) --check
@$(LOCAL_PYTHON_BIN) -m isort $(LINT_ENFORCE_DIRS) --check-only

.PHONY: clean
clean:
Expand Down
7 changes: 2 additions & 5 deletions bin/addheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,11 @@ def add_header(path, var_dict, explicit_border=True, block_wrap=False):
END_MARKER,
)
if block_wrap:
lic = (
"""
lic = """
/*
%s
*/
"""
% lic
)
""" % lic

module_header.append(lic)
# Make sure there's a blank line between license header and code
Expand Down
132 changes: 68 additions & 64 deletions bin/showaccounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in bin/showaccounting.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand All @@ -39,7 +39,7 @@
from mig.shared.defaults import gdp_distinguished_field


def usage(name='showaccounting.py'):
def usage(name="showaccounting.py"):
"""Usage help"""

print("""Create accounting information based on quota.
Expand All @@ -53,33 +53,31 @@
-m Minimum usage Only show accounts using more than
minimum usage (TB).
-t TIMESTAMP Use specific timestamp, latest if unset
""" % {'name': name})
""" % {"name": name})


def show_accounting(configuration,
timestamp,
user_filter,
minimum_usage,
verbose):
def show_accounting(
configuration, timestamp, user_filter, minimum_usage, verbose
):
"""Print user accounting report"""
user_filter_re = None
if user_filter:
try:
user_filter_re = re.compile(user_filter)
except Exception as err:
print("ERROR: Failed to compile user_filter: %r error: %s"
% (user_filter, err))
print(
"ERROR: Failed to compile user_filter: %r error: %s"
% (user_filter, err)
)
return

usage = get_usage(configuration,
timestamp=timestamp,
verbose=verbose)
usage = get_usage(configuration, timestamp=timestamp, verbose=verbose)

accounting = usage.get('accounting', {})
accounting_timestamp = usage.get('timestamp', 0)
accounting_datestr \
= datetime.datetime.fromtimestamp(accounting_timestamp) \
.strftime('%d/%m/%Y-%H:%M:%S')
accounting = usage.get("accounting", {})
accounting_timestamp = usage.get("timestamp", 0)
accounting_datestr = datetime.datetime.fromtimestamp(
accounting_timestamp
).strftime("%d/%m/%Y-%H:%M:%S")

# Sorted by total bytes and print usage for users

Expand All @@ -91,14 +89,19 @@
for username, values in accounting.items():
# Do not show GDP project users
# projects are accounted for by the main user
if configuration.site_enable_gdp \
and username.find("/%s=" % gdp_distinguished_field) != -1:
if (
configuration.site_enable_gdp
and username.find("/%s=" % gdp_distinguished_field) != -1
):
continue
report_total_users += 1
total_bytes = values.get('total_bytes', 0)
total_bytes = values.get("total_bytes", 0)
report_total_bytes += total_bytes
if total_bytes < minimum_usage \
or user_filter_re and not user_filter_re.fullmatch(username):
if (
total_bytes < minimum_usage
or user_filter_re
and not user_filter_re.fullmatch(username)
):
continue
report_shown_users += 1
report_shown_bytes += total_bytes
Expand All @@ -107,33 +110,36 @@
total_bytes_map[total_bytes] = total_bytes_map_userlist
sorted_total_bytes = sorted(list(total_bytes_map), reverse=True)

print("\nAccounting (%d) %s for storage quota(s):"
% (accounting_timestamp, accounting_datestr))
for quota_fs, values in usage.get('quota', {}).items():
quota_mtime = values.get('mtime', 0)
quota_datestr = datetime.datetime.fromtimestamp(quota_mtime) \
.strftime('%d/%m/%Y-%H:%M:%S')
print(" - %s (%d) %s" % (quota_fs,
quota_mtime,
quota_datestr))

print("Found a total of %s users using %s storage"
% (report_total_users,
human_readable_filesize(report_total_bytes)))
print("Showing details for %s users using %s storage "
% (report_shown_users,
human_readable_filesize(report_shown_bytes)))
print(
"\nAccounting (%d) %s for storage quota(s):"
% (accounting_timestamp, accounting_datestr)
)
for quota_fs, values in usage.get("quota", {}).items():
quota_mtime = values.get("mtime", 0)
quota_datestr = datetime.datetime.fromtimestamp(quota_mtime).strftime(
"%d/%m/%Y-%H:%M:%S"
)
print(" - %s (%d) %s" % (quota_fs, quota_mtime, quota_datestr))

print(
"Found a total of %s users using %s storage"
% (report_total_users, human_readable_filesize(report_total_bytes))
)
print(
"Showing details for %s users using %s storage "
% (report_shown_users, human_readable_filesize(report_shown_bytes))
)
print("User filter: %r" % user_filter)
print("Minimum usage: %s" % human_readable_filesize(minimum_usage))
for total_bytes in sorted_total_bytes:
total_bytes_human = human_readable_filesize(total_bytes)
for username in total_bytes_map[total_bytes]:
report = accounting[username]
home_report = report.get('home_report', '')
freeze_report = report.get('freeze_report', '')
vgrid_report = report.get('vgrid_report', '')
ext_users_report = report.get('ext_users_report', '')
peers_report = report.get('peers_report', '')
home_report = report.get("home_report", "")
freeze_report = report.get("freeze_report", "")
vgrid_report = report.get("vgrid_report", "")
ext_users_report = report.get("ext_users_report", "")
peers_report = report.get("peers_report", "")
print("\n%s:" % username)
print("Total usage: %s" % total_bytes_human)
if home_report:
Expand All @@ -148,46 +154,44 @@
print(peers_report)


if '__main__' == __name__:
if "__main__" == __name__:
conf_path = None
user_filter = None
timestamp = 0
minimum_usage = 0
verbose = False
opt_args = 'hvc:f:m:t:'
opt_args = "hvc:f:m:t:"
try:
(opts, args) = getopt.getopt(sys.argv[1:], opt_args)
for (opt, val) in opts:
if opt == '-h':
opts, args = getopt.getopt(sys.argv[1:], opt_args)
for opt, val in opts:
if opt == "-h":
usage()
sys.exit(0)
if opt == '-v':
if opt == "-v":
verbose = True
elif opt == '-c':
elif opt == "-c":
conf_path = val
elif opt == '-f':
elif opt == "-f":
user_filter = val
elif opt == '-m':
minimum_usage = float(val)*(1024**4)
elif opt == '-t':
elif opt == "-m":
minimum_usage = float(val) * (1024**4)
elif opt == "-t":
timestamp = int(val)
else:
print('Error: %s not supported!' % opt)
print("Error: %s not supported!" % opt)
usage()
sys.exit(1)
except getopt.GetoptError as err:
print('Error: ', err.msg)
print("Error: ", err.msg)
usage()
sys.exit(1)

configuration = get_configuration_object(config_file=conf_path,
skip_log=True,
disable_auth_log=True)
configuration = get_configuration_object(
config_file=conf_path, skip_log=True, disable_auth_log=True
)

show_accounting(configuration,
timestamp,
user_filter,
minimum_usage,
verbose)
show_accounting(
configuration, timestamp, user_filter, minimum_usage, verbose
)

sys.exit(0)
5 changes: 2 additions & 3 deletions bin/verifyvgridformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Check warning on line 23 in bin/verifyvgridformat.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand Down Expand Up @@ -49,8 +49,7 @@
-v|--verbose Verbose output
-c PATH|--config=PATH Path to config file
-n NAME|--name=NAME Only verify specific vgrid
"""
% {"name": name},
""" % {"name": name},
file=sys.stderr,
)

Expand Down Expand Up @@ -78,7 +77,7 @@
vgrid_dirpath = os.path.join(root, dirent)
owners_filepath = os.path.join(vgrid_dirpath, "owners")
if os.path.isfile(owners_filepath):
vgrid = vgrid_dirpath[len(configuration.vgrid_home):].strip(
vgrid = vgrid_dirpath[len(configuration.vgrid_home) :].strip(

Check warning on line 80 in bin/verifyvgridformat.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

whitespace before ':'
os.sep
)
vgrid_mapping[vgrid] = vgrid_flat_name(vgrid, configuration)
Expand Down
Loading
Loading