Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions mig/shared/init.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand All @@ -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 mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)

Check warning on line 23 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand All @@ -31,13 +31,16 @@

import mimetypes
import os
import time

from mig.shared.base import requested_backend, extract_field
from mig.shared.conf import get_configuration_object
from mig.shared.htmlgen import themed_styles, themed_scripts
from mig.shared.settings import load_settings, load_widgets, load_profile

title_style_helpers = {'base': '', 'advanced': '', 'page': '', 'skin': ''}
title_script_helpers = {'base': '', 'advanced': '', 'skin': '', 'page': '',
'init': '', 'ready': '', 'body': ''}


def make_basic_entry(kind, values):
"""Create basic entry for output_objects"""
Expand All @@ -51,10 +54,14 @@
return make_basic_entry('start', {'headers': headers})


def make_title_entry(text, meta='', style={}, script={}, skipmenu=False,
def make_title_entry(text, meta='', style=None, script=None, skipmenu=False,
skipwidgets=False, skipuserstyle=False,
skipuserprofile=False, backend=''):
"""Create title entry for output_objects"""
if style is None:
style = title_style_helpers.copy()
if script is None:
script = title_script_helpers.copy()
return make_basic_entry('title', {'text': text,
'meta': meta,
'style': style,
Expand Down Expand Up @@ -88,7 +95,7 @@
return -1


def start_download(configuration, path, output):

Check failure on line 98 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'start_download' (60% confidence)

Check failure on line 98 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'start_download' (60% confidence)
"""Helper to set the headers required to force a file download instead of
plain output delivery. Automatically detects mimetype of path and sets
content size to size of output.
Expand All @@ -108,7 +115,7 @@
% os.path.basename(path))])


def start_error(configuration, output_format, status_pair):

Check failure on line 118 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'start_error' (60% confidence)

Check failure on line 118 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'start_error' (60% confidence)
"""Helper to set the headers required to force an error message to be shown
in particular in cases where file or binary output delivery was requested,
which would hide the error in the file.
Expand All @@ -124,7 +131,7 @@
('Status', '%s %s' % status_pair)])


def initialize_main_variables(client_id, op_title=True, op_header=True,

Check failure on line 134 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'initialize_main_variables' (60% confidence)

Check failure on line 134 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'initialize_main_variables' (60% confidence)
op_menu=True, configuration=None):
"""Script initialization is identical for most scripts in
shared/functionality. This function should be called in most cases.
Expand Down Expand Up @@ -169,7 +176,7 @@
if settings:
title['user_settings'] = settings
base_menu = settings.get('SITE_BASE_MENU', 'default')
if not base_menu in configuration.site_base_menu:
if base_menu not in configuration.site_base_menu:
base_menu = 'default'
if base_menu == 'simple' and configuration.site_simple_menu:
title['base_menu'] = configuration.site_simple_menu
Expand All @@ -193,7 +200,7 @@
if profile_image_list:
# TODO: copy profile image e.g. to /user_home/avatars/X
# and use it from there instead
profile_image = os.path.join(configuration.site_user_redirect,

Check warning on line 203 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (82 > 80 characters)

Check warning on line 203 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (82 > 80 characters)
profile_image_list[-1])
else:
profile_image = ''
Expand All @@ -214,7 +221,7 @@
return (configuration, logger, output_objects, op_name)


def extract_menu(configuration, title_entry):

Check failure on line 224 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'extract_menu' (60% confidence)

Check failure on line 224 in mig/shared/init.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'extract_menu' (60% confidence)
"""Extract the list of active menu items from title_entry. Useful to
detect if a particular feature should be enabled for this particular set
of default and user configured menu items.
Expand Down
42 changes: 17 additions & 25 deletions mig/shared/output.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
Expand All @@ -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 mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)

Check warning on line 23 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (81 > 80 characters)
#
# -- END_HEADER ---
#
Expand All @@ -33,7 +33,7 @@
try:
from future import standard_library
standard_library.install_aliases()
except Exception as exc:
except Exception:
print("ERROR: failed to init compatibility helpers")
exit(1)

Expand All @@ -49,12 +49,11 @@
from mig.shared.bailout import bailout_title, crash_helper, \
filter_output_objects
from mig.shared.base import force_native_str, hexlify
from mig.shared.defaults import file_dest_sep, keyword_any, keyword_updating
from mig.shared.base import hexlify
from mig.shared.defaults import file_dest_sep, keyword_any, keyword_updating
from mig.shared.defaults import file_dest_sep, keyword_updating
from mig.shared.htmlgen import get_xgi_html_header, get_xgi_html_footer, \
vgrid_items, html_post_helper, tablesorter_pager
from mig.shared.init import find_entry, find_entry_index
from mig.shared.init import find_entry, find_entry_index, \
title_script_helpers, title_style_helpers
from mig.shared.objecttypes import validate
from mig.shared.prettyprinttable import pprint_table
from mig.shared.pwcrypto import sorted_hash_algos
Expand All @@ -66,7 +65,7 @@
'yaml', 'xmlrpc', 'resource', 'json', 'file']


def kwargs_for_functionality(main, configuration=None, environ=None):

Check failure on line 68 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'kwargs_for_functionality' (60% confidence)

Check failure on line 68 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'kwargs_for_functionality' (60% confidence)
parameters = inspect.signature(main).parameters

kwargs = dict()
Expand All @@ -77,7 +76,7 @@
return kwargs


def reject_main(client_id, user_arguments_dict):

Check failure on line 79 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_arguments_dict' (100% confidence)

Check failure on line 79 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'reject_main' (60% confidence)

Check failure on line 79 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused variable 'user_arguments_dict' (100% confidence)

Check failure on line 79 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'reject_main' (60% confidence)
"""A simple main-function to use if functionality backend is disabled"""
output_objs = [bailout_title(None, 'Access Error'),
{'object_type': 'header', 'text': 'Access Error'},
Expand All @@ -86,7 +85,7 @@
return (output_objs, returnvalues.CLIENT_ERROR)


def dummy_main(client_id, user_arguments_dict):

Check failure on line 88 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'dummy_main' (60% confidence)

Check failure on line 88 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

unused function 'dummy_main' (60% confidence)
"""Dummy main-function to override with backend import"""
output_objs = [bailout_title(None, 'Internal Error'),
{'object_type': 'header', 'text': 'Internal Error'},
Expand Down Expand Up @@ -392,7 +391,7 @@
content_keys = ['share_id', 'path']
mangle_fields = ['access', 'created', 'invites']
for (key, title) in optional_cols:
if not key in skip_list:
if key not in skip_list:
header[0].append(title)
# Some fields need mangling for text print
if key in mangle_fields:
Expand Down Expand Up @@ -516,7 +515,7 @@
% obj)
if 'vgrid' in obj:
lines.append('%s: %s'
% (configuration.site_vgrid_label, obj['vgrid']))

Check warning on line 518 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (86 > 80 characters)

Check warning on line 518 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (86 > 80 characters)
if 'finished_timestamp' in obj:
lines.append('Finished: %(finished_timestamp)s\n'
% obj)
Expand All @@ -534,20 +533,20 @@
% count)
if 'queued' in single_history:
lines.append('Queued %s: %s\n' % (count,
single_history['queued']))

Check warning on line 536 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (88 > 80 characters)

Check warning on line 536 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (88 > 80 characters)
if 'executing' in single_history:
lines.append('Executing %s: %s\n' % (count,
single_history['executing']))

Check warning on line 539 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (94 > 80 characters)

Check warning on line 539 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (94 > 80 characters)
if 'resource' in single_history:
lines.append('Resource %s: %s\n' % (count,
single_history['resource']))

Check warning on line 542 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (92 > 80 characters)

Check warning on line 542 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (92 > 80 characters)
if 'vgrid' in single_history:
lines.append('%s %s: %s' %
(configuration.site_vgrid_label,
count, single_history['vgrid']))
if 'failed' in single_history:
lines.append('Failed %s: %s\n' % (count,
single_history['failed']))

Check warning on line 549 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (88 > 80 characters)

Check warning on line 549 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (88 > 80 characters)
if 'failed_message' in single_history:
lines.append('Failed message %s: %s\n'
% (count,
Expand Down Expand Up @@ -582,7 +581,6 @@
if len(i['dir_listings']) == 0:
continue
columns = 6
cols = 0
if i.get('show_dest', False):
columns += 1
for dir_listing in i['dir_listings']:
Expand Down Expand Up @@ -780,7 +778,7 @@
html_escape(i['text']))
elif i['object_type'] == 'header':
lines.append('<h1 class="header %s">%s</h1>' % (i.get('class', ''),
html_escape(i['text'])))

Check warning on line 781 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (84 > 80 characters)

Check warning on line 781 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (84 > 80 characters)
elif i['object_type'] == 'sectionheader':
lines.append('<h3 class="sectionheader %s">%s</h3>' %
(i.get('class', ''), html_escape(i['text'])))
Expand All @@ -788,15 +786,13 @@
meta = i.get('meta', '')
backend = i.get('backend', '')
style_entry = i.get('style', '')
style_helpers = {'base': '', 'advanced': '', 'page': '',
'skin': ''}
style_helpers = title_style_helpers.copy()
if isinstance(style_entry, dict):
style_helpers.update(style_entry)
else:
style_helpers['base'] += style_entry
script_entry = i.get('script', '')
script_helpers = {'base': '', 'advanced': '', 'skin': '',
'page': '', 'init': '', 'ready': '', 'body': ''}
script_helpers = title_script_helpers.copy()
if isinstance(script_entry, dict):
script_helpers.update(script_entry)
else:
Expand Down Expand Up @@ -1115,9 +1111,6 @@
elif i['object_type'] == 'html_form':
lines.append(i['text'])
elif i['object_type'] == 'dir_listings':
redirect_name = i.get('redirect_name',
configuration.site_user_redirect)
redirect_path = i.get('redirect_path', redirect_name)
ls_url_template = i['ls_url_template']
rmdir_url_template = i['rmdir_url_template']
rm_url_template = i['rm_url_template']
Expand Down Expand Up @@ -1164,7 +1157,7 @@
len(dir_listing['entries'])))
cols += 1
lines.append(
'''<td class="empty_cell narrow" colspan="%d"></td>

Check warning on line 1160 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (83 > 80 characters)

Check warning on line 1160 in mig/shared/output.py

View workflow job for this annotation

GitHub Actions / Style check python and annotate

line too long (83 > 80 characters)
''' % (columns - cols))
lines.append('</tr>')
cols = columns
Expand Down Expand Up @@ -1935,7 +1928,7 @@
<th>Path</th>
''')
for (key, title) in optional_cols:
if not key in skip_list:
if key not in skip_list:
lines.append('<th>%s</th>' % title)
lines.append('''
</tr>
Expand All @@ -1945,28 +1938,27 @@
for single_share in sharelinks:
openlink = single_share.get('opensharelink', '')
openlink_html = ''
if openlink and not 'opensharelink' in skip_list:
if openlink and 'opensharelink' not in skip_list:
openlink_html = html_link(openlink)
editlink = single_share.get('editsharelink', '')
editlink_html = ''
if editlink and not 'editsharelink' in skip_list:
if editlink and 'editsharelink' not in skip_list:
editlink_html = html_link(editlink)
else:
# Leave the icon space empty if not set (used in edit)
editlink_html = '<span class="iconleftpad"></span>'
dellink = single_share.get('delsharelink', '')
dellink_html = ''
if dellink and not 'delsharelink' in skip_list:
if dellink and 'delsharelink' not in skip_list:
dellink_html = html_link(dellink)
access = ' & '.join(single_share['access'])
lines.append('''
<tr>
<td>%s</td><td class="centertext">%s%s%s</td><td>%s</td>''' % (single_share['share_id'],
openlink_html, editlink_html,
dellink_html,
single_share['path']))
for (key, title) in optional_cols:
if not key in skip_list:
if key not in skip_list:
if isinstance(single_share[key], basestring):
val = single_share[key]
elif isinstance(single_share[key], list):
Expand Down Expand Up @@ -2104,7 +2096,7 @@
page_entries = i.get('page_entries', [5, 10, 20, 25, 40, 50, 80,
100, 250, 500, 1000])
default_entries = i.get('default_entries', 20)
if not default_entries in page_entries:
if default_entries not in page_entries:
page_entries.append(default_entries)
form_prepend = i.get('form_prepend', '')
form_append = i.get('form_append', '')
Expand Down Expand Up @@ -2701,7 +2693,7 @@
for entry in out_obj:
if entry.get('wrap_binary', False):
for key in entry.get('wrap_targets', []):
if not key in entry:
if key not in entry:
continue
entry[key] = xmlrpc.client.Binary(entry[key])
return xmlrpc.client.dumps((out_obj, ), allow_none=True)
Expand Down Expand Up @@ -2796,7 +2788,7 @@
"""Lookup the format helper function for outputformat name, with fallback
to default_format if not available.
"""
if not name in _valid_output_formats:
if name not in _valid_output_formats:
if default_format in _valid_output_formats:
# Fall back to default format
name = default_format
Expand Down Expand Up @@ -2824,7 +2816,7 @@

logger = configuration.logger
# logger.debug("format output to %s" % outputformat)
valid_formats = get_valid_outputformats()
# valid_formats = get_valid_outputformats()
(val_ret, val_msg) = validate(out_obj, configuration)
if not val_ret:
logger.error("%s formatting failed: %s (%s)" %
Expand Down Expand Up @@ -2871,7 +2863,7 @@
}] + out_obj

# NOTE: strip wsgi helpers and info unless needed for output formatting
if not outputformat in ('txt', 'html', 'file'):
if outputformat not in ('txt', 'html', 'file'):
out_obj = [i for i in out_obj if i['object_type'] != 'wsgi']

# logger.debug("%s formatting output" % outputformat)
Expand Down
Loading