Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
search_interface_default_urlargd)
if em != "":
em = em.split(",")
# get user ID:
try:
uid = getUid(req)
user_preferences = {}
if uid == -1:
return page_not_authorized(req, "../",
text="You are not authorized to view this collection",
navmenuid='search')
elif uid > 0:
user_preferences = get_user_preferences(uid)
except Error:
register_exception(req=req, alert_admin=True)
return page(title=_("Internal Error"),
body=create_error_box(req, verbose=verbose, ln=ln),
description="%s - Internal Error" % CFG_SITE_NAME,
keywords="%s, Internal Error" % CFG_SITE_NAME,
language=ln,
req=req,
navmenuid='search')
# start display:
req.content_type = "text/html"
req.send_http_header()
# deduce collection id:
colID = get_colID(get_coll_normalised_name(c))
if type(colID) is not int:
page_body = '<p>' + (_("Sorry, collection %s does not seem to exist.") % ('<strong>' + str(c) + '</strong>')) + '</p>'
page_body = '<p>' + (_("You may want to start browsing from %s.") % ('<a href="' + CFG_SITE_URL + '?ln=' + ln + '">' + get_coll_i18nname(CFG_SITE_NAME, ln) + '</a>')) + '</p>'
if req.header_only:
@param recIDs: list of record IDs with control_no
@type recIDs: list of int
@param control_no: the control number of the authority record in question
@type control_no: string
"""
if len(recIDs) > 1:
error_message = \
"DB inconsistency: multiple rec_ids " + \
"(" + ", ".join([str(recID) for recID in recIDs]) + ") " + \
"found for authority record control number: " + control_no
try:
raise Exception
except:
register_exception(prefix=error_message,
alert_admin=True,
subject=error_message)
Displays a warning if we find out that etc/biformat dir is not writable by us
(as most opeation of BibFormat must write in this directory).
@param req: the request object
@param ln: language
@return: a web page
"""
warnings = []
ln = wash_language(ln)
_ = gettext_set_language(ln)
if not bibformatadminlib.can_write_etc_bibformat_dir():
try:
raise InvenioBibFormatWarning(_('Cannot write in etc/bibformat dir of your Invenio installation. Check directory permission.'))
except InvenioBibFormatWarning, exc:
register_exception(stream='warning', req=req)
warnings.append(exc.message)
# Check if user is authorized to administer
# If not, still display page but offer to log in
try:
uid = getUid(req)
except:
return error_page('Error', req)
(auth_code, auth_msg) = check_user(req, 'cfgbibformat')
if not auth_code:
is_admin = True
else:
is_admin = False
navtrail = '''<a href="%s/help/admin" class="navtrail">%s</a>''' % \
(CFG_SITE_SECURE_URL, _("Admin Area"))
def bibsched_send_signal(proc, task_id, signal):
"""Send a signal to a given task."""
try:
pid = get_task_pid(proc, task_id, True)
os.kill(pid, signal)
except OSError:
pass
except KeyError:
register_exception()
def delete_oai_set(oai_set_id):
""""""
try:
run_sql("DELETE FROM oaiREPOSITORY WHERE id=%s", (oai_set_id,))
return (1, "")
except StandardError, e:
register_exception(alert_admin=True)
return (0, e)
try:
## We copy the input file and we make it available to OpenOffice
## with the user nobody
from invenio.bibdocfile import decompose_file
input_format = decompose_file(input_file, skip_version=True)[2]
fd, tmpinputfile = tempfile.mkstemp(dir=CFG_TMPDIR, suffix=normalize_format(input_format))
os.close(fd)
shutil.copy(input_file, tmpinputfile)
get_file_converter_logger().debug("Prepared input file %s" % tmpinputfile)
os.chmod(tmpinputfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
tmpoutputfile = tempfile.mktemp(dir=CFG_OPENOFFICE_TMPDIR, suffix=normalize_format(output_format))
get_file_converter_logger().debug("Prepared output file %s" % tmpoutputfile)
try:
execute_command(os.path.join(CFG_BINDIR, 'inveniounoconv'), '-vvv', '-s', CFG_OPENOFFICE_SERVER_HOST, '-p', str(CFG_OPENOFFICE_SERVER_PORT), '--output', tmpoutputfile, '-f', unoconv_format, tmpinputfile, sudo=CFG_OPENOFFICE_USER)
except:
register_exception(alert_admin=True)
raise
except InvenioWebSubmitFileConverterError:
## Ok maybe OpenOffice hanged. Let's better kill it and restarted!
if CFG_OPENOFFICE_SERVER_HOST != 'localhost':
## There's not that much that we can do. Let's bail out
if not os.path.exists(tmpoutputfile) or not os.path.getsize(tmpoutputfile):
raise
else:
## Sometimes OpenOffice crashes but we don't care :-)
## it still have created a nice file.
pass
else:
execute_command(os.path.join(CFG_BINDIR, 'inveniounoconv'), '-vvv', '-k', sudo=CFG_OPENOFFICE_USER)
## NOTE: in case we switch back keeping LibreOffice running, uncomment
## the following lines.
#_unregister_unoconv()
try:
newname = normalize_docname(newname)
res = run_sql("SELECT b.id FROM bibrec_bibdoc bb JOIN bibdoc b on bb.id_bibdoc=b.id WHERE bb.id_bibrec=%s AND b.docname=%s", (self.recid, newname))
if res:
raise InvenioWebSubmitFileError, "A bibdoc called %s already exists for recid %s" % (newname, self.recid)
try:
for f in os.listdir(self.basedir):
if not f.startswith('.'):
try:
(dummy, base, extension, version) = decompose_file_with_version(f)
except ValueError:
register_exception(alert_admin=True, prefix="Strange file '%s' is stored in %s" % (f, self.basedir))
else:
shutil.move(os.path.join(self.basedir, f), os.path.join(self.basedir, '%s%s;%i' % (newname, extension, version)))
except Exception, e:
register_exception()
raise InvenioWebSubmitFileError("Error in renaming the bibdoc %s to %s for recid %s: %s" % (self.docname, newname, self.recid, e))
run_sql("update bibdoc set docname=%s where id=%s", (newname, self.id,))
self.docname = newname
finally:
Md5Folder(self.basedir).update()
self.touch()
self._build_file_list('rename')
self._build_related_file_list()
@param uid: user ID
@param grpID: ID of the group
@param member_id: selected member ID
@param ln: language
@return: body with warnings
"""
body = ''
warnings = []
infos = []
_ = gettext_set_language(ln)
user_status = db.get_user_status(uid, grpID)
if not len(user_status):
try:
raise InvenioWebSessionError(_('Sorry, there was an error with the database.'))
except InvenioWebSessionError, exc:
register_exception()
body = websession_templates.tmpl_error(exc.message, ln)
return body
if member_id == -1:
try:
raise InvenioWebSessionWarning(_('Please choose a member if you want to remove him from the group.'))
except InvenioWebSessionWarning, exc:
register_exception(stream='warning')
warnings.append(exc.message)
body = perform_request_manage_member(uid,
grpID,
warnings=warnings,
ln=ln)
else:
db.delete_member(grpID, member_id)
infos.append(CFG_WEBSESSION_INFO_MESSAGES["MEMBER_DELETED"])
body = perform_request_manage_member(uid,
else:
try:
raise InvenioBibFormatBfxError(_('No name defined for the template.'))
except InvenioBibFormatBfxError, exc:
register_exception()
logging.error(exc.message)
return None
#get template description
if attrs.has_key('description'):
description = attrs['description']
else:
description = ''
try:
raise InvenioBibFormatBfxWarning(_('No description entered for the template.'))
except InvenioBibFormatBfxWarning, exc:
register_exception(stream='warning')
logging.warning(exc.message)
self.templates[name]['description'] = description
#get content-type of resulting output
if attrs.has_key('content'):
content_type = attrs['content']
else:
content_type = 'text/xml'
try:
raise InvenioBibFormatBfxWarning(_('No content type specified for the template. Using default: text/xml.'))
except InvenioBibFormatBfxWarning, exc:
register_exception(stream='warning')
logging.warning(exc.message)
self.templates[name]['content_type'] = content_type
#walk node
self.walk(node, out_file)
return None
## handle something correctly.
## Convert this error into an
## InvenioWebSubmitFunctionError and raise it:
msg = "Unhandled TypeError caught when " \
"calling [%s] WebSubmit function: " \
"[%s]: \n%s" % (function_name, str(err), traceback.format_exc())
raise InvenioWebSubmitFunctionError(msg)
except InvenioWebSubmitFunctionWarning, err:
## There was an unexpected behaviour during the
## execution. Log the message into function's log
## and go to next function
log_function(curdir, "***Warning*** from %s: %s" \
% (function_name, str(err)), start_time)
## Reset "func_returnval" to None:
func_returnval = None
register_exception(req=req, alert_admin=True, prefix="Warning in executing function %s with globals %s" % (pprint.pformat(currfunction), pprint.pformat(the_globals)))
log_function(curdir, "End %s" % function_name, start_time)
if func_returnval is not None:
## Append the returned value as a string:
currfunction['text'] = str(func_returnval)
else:
## The function the NoneType. Don't keep that value as
## the currfunction->text. Replace it with the empty
## string.
currfunction['text'] = ""
else:
currfunction['error'] = 1
functions.append(currfunction)
except InvenioWebSubmitFunctionStop, err:
## The submission asked to stop execution. This is
## ok. Do not alert admin, and raise exception further
log_function(curdir, "***Stop*** from %s: %s" \