# The secret is a 64 chars string that is used to sign the request
# The generated signature is a SHA256 hes digest
-from __future__ import print_function
-
import urllib, urllib2
import threading
import hmac
import time
import datetime
from myslice.configengine import ConfigEngine
+from myslice.settings import logger
+
config = ConfigEngine()
if config.activity and config.activity.apikey :
def logWrite(request, action, message, objects = None):
if not apikey :
- print("===============>> activity: no apikey")
+ logger.info("===============>> activity: no apikey")
return
if not secret :
- print("===============>> activity: no secret")
+ logger.info("===============>> activity: no secret")
return
timestamp = time.mktime(datetime.datetime.today().timetuple())
try :
result = urllib2.urlopen(server, urllib.urlencode(log))
- print("===============>> activity: %s <%s> %s" % (action, request.user,message))
+ logger.info("===============>> activity: {} <{}> {}".format(action, request.user,message))
content = result.read()
except urllib2.URLError as e:
- print("===============>> activity: connection to " + server + " impossible, could not log action")
- print(e.strerror)
- print("")
+ logger.error("===============>> activity: connection to {} impossible, could not log action".format(server))
+ logger.error(e.strerror)
def log(request, action, message, objects = None):
# Create a new thread in Daemon mode to send the log entry
except Exception as e:
logger.error("Exception in Manifold Auth Backend: {}".format(e))
import traceback
- traceback.print_exc()
+ logger.error(traceback.format_exc())
return None
try:
-from __future__ import print_function
-
from django.contrib.auth import logout
from django.http import HttpResponseRedirect
+from myslice.settings import logger
+
import activity.user
# hard question : where should we redirect requests to logout if user is not logged in ?
# check that we're indeed logged in
if not request.user.is_authenticated():
return HttpResponseRedirect ('/')
- print("LOGGING OUT")
+ logger.info("LOGGING OUT")
# log user activity
activity.user.logout(request)
# Manifold API Python interface
-from __future__ import print_function
-
import copy
import xmlrpclib
import ssl
return ResultValue(**result)
except Exception as error:
- print("===== xmlrpc catch-all exception:", error)
+ logger.error("===== xmlrpc catch-all exception: {}".format(error))
import traceback
- traceback.print_exc(limit=3)
+ logger.error(traceback.format_exc(limit=3))
if "Connection refused" in error:
raise ManifoldException ( ManifoldResult (code=ManifoldCode.SERVER_UNREACHABLE,
-from __future__ import print_function
-
import json
import os.path
from manifoldresult import ManifoldException
from manifold.util.log import Log
-from myslice.settings import config, logger, DEBUG
+from myslice.settings import config, logger
# register activity
import activity.slice
# expecting a POST
if request.method != 'POST':
- logger.error("MANIFOLDPROXY unexpected method %s -- exiting" % request.method)
+ logger.error("MANIFOLDPROXY unexpected method {} -- exiting".format(request.method))
return HttpResponse ({"ret":0}, mimetype="application/json")
# we only support json for now
# if needed in the future we should probably cater for
# format_in : how is the query encoded in POST
# format_out: how to serve the results
if format != 'json':
- logger.error("MANIFOLDPROXY unexpected format %s -- exiting" % format)
+ logger.error("MANIFOLDPROXY unexpected format {} -- exiting".format(format))
return HttpResponse ({"ret":0}, mimetype="application/json")
try:
# translate incoming POST request into a query object
- #logger.debug("MANIFOLDPROXY request.POST %s" % request.POST)
+ #logger.debug("MANIFOLDPROXY request.POST {}".format(request.POST))
manifold_query = Query()
#manifold_query = ManifoldQuery()
#
# resource reservation
if (manifold_query.action.lower() == 'update') :
- print(result['value'][0])
+ logger.debug(result['value'][0])
if 'resource' in result['value'][0] :
for resource in result['value'][0]['resource'] :
activity.slice.resource(request,
return HttpResponse (json_answer, mimetype="application/json")
- except Exception,e:
- logger.error("MANIFOLDPROXY %s" % e)
+ except Exception as e:
+ logger.error("MANIFOLDPROXY {}".format(e))
import traceback
- traceback.print_exc()
+ logger.error(traceback.format_exc())
return HttpResponse ({"ret":0}, mimetype="application/json")
####################
# this however turns out disappointing/not very informative
failure_answer=[ "csrf_failure" ]
def csrf_failure(request, reason=""):
- print("CSRF failure with reason '%s'"%reason)
+ logger.error("CSRF failure with reason '{}'".format(reason))
return HttpResponseForbidden (json.dumps (failure_answer), mimetype="application/json")
-from __future__ import print_function
-
import json
import os.path
from django.contrib import messages
+from myslice.settings import logger
+
debug=False
#debug=True
# xxx need a way to export error messages to the UI
if result['code'] == 1: # warning
# messages.warning(request, result['description'])
- print(("METADATA WARNING -",request,result['description']))
+ logger.warning(("METADATA WARNING - {} {}".format(request,result['description'])))
elif result['code'] == 2:
# messages.error(request, result['description'])
- print(("METADATA ERROR -",request,result['description']))
+ logger.error(("METADATA ERROR - {} {}".format(request,result['description'])))
# XXX FAIL HERE XXX
return
return self.hash_by_object[object]['column'].sort()
def get_field_type(self, object, field):
- if debug: print("Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon")
+ if debug:
+ logger.debug("Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon")
return field
__import__(component)
u.append( url(r'^%s/' % component, include('%s.urls' % component)) )
except Exception, e:
- logger.info("Cannot load component (%s): %s" % (component, e))
+ logger.error("Cannot load component ({}): {}".format(component, e))
else:
- logger.info("Loaded component %s" % component)
+ logger.info("Loaded component {}".format(component))
return u
ROOT = os.path.realpath(os.path.dirname(__file__) + '/..')
except:
import traceback
- traceback.print_exc()
+ logger.error(traceback.format_exc())
from myslice.configengine import ConfigEngine
for aux in auxiliaries:
if os.path.isdir(os.path.join(ROOT,aux)):
- print(("Using devel auxiliary",aux))
+ logger.info("Using devel auxiliary {}".format(aux))
INSTALLED_APPS.append(aux)
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class QueryGrid (Plugin):
"""A plugin for displaying a query as a list
if self.checkboxes:
# we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
if 'aoColumns' in self.datatables_options:
- print('WARNING: querygrid uses aoColumnDefs, your aoColumns spec. is discarded')
+ logger.warning('WARNING: querygrid uses aoColumnDefs, your aoColumns spec. is discarded')
del self.datatables_options['aoColumns']
# set aoColumnDefs in datatables_options - might already have stuff in there
aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class QueryTable (Plugin):
"""A plugin for displaying a query as a list
_columns = columns
_hidden_columns = []
elif self.query:
- print("self.query.fields = ", self.query_all.fields)
+ logger.debug("self.query.fields = {}".format(self.query_all.fields))
# Columns displayed by default
if self.default_fields is not None:
_columns = [field for field in self.default_fields if not field == 'urn']
if query_all:
# We need a list because sets are not JSON-serializable
if self.default_fields is not None:
- print(self.query_all.fields)
+ logger.debug(self.query_all.fields)
_hidden_columns = list(self.query_all.fields - set(self.default_fields))
else:
_hidden_columns = list(self.query_all.fields - self.query.fields)
_columns = []
_hidden_columns = []
- print("_columns=", _columns)
+ logger.debug("_columns={}".format(_columns))
self.columns = { self.mapping.get(c, c) : c for c in _columns }
self.hidden_columns = { self.mapping.get(c, c) : c for c in _hidden_columns }
- print("self.columns", self.columns)
- print("self.hidden_columns", self.hidden_columns)
+ logger.debug("self.columns {}".format(self.columns))
+ logger.debug("self.hidden_columns {}".format(self.hidden_columns))
self.init_key=init_key
self.datatables_options=datatables_options
if self.checkboxes:
# we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
if 'aoColumns' in self.datatables_options:
- print('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
+ logger.warning('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
del self.datatables_options['aoColumns']
# set aoColumnDefs in datatables_options - might already have stuff in there
aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class Univbris(Plugin):
def __init__ (self, query=None, **settings):
Plugin.__init__ (self, **settings)
self.query=query
self.query_uuid = query.query_uuid if query else None
- print("called univbris plugin")
+ logger.info("called univbris plugin")
def template_file (self):
try:
return "univbris_welcome.html"
- except Exception:
- print("error template")
+ except Exception as e:
+ logger.error("error template {}".format(e))
def requirements (self):
reqs = {
- 'js_files' : [ "js/spin-presets.js", "js/spin.min.js", "js/jquery.spin.js",
- "js/manifold.js", "js/manifold-query.js",
- "js/unfold-helper.js",
- 'js/univbris.js',
+ 'js_files' : [
+ "js/spin-presets.js", "js/spin.min.js", "js/jquery.spin.js",
+ "js/manifold.js", "js/manifold-query.js",
+ "js/unfold-helper.js",
+ 'js/univbris.js',
],
'css_files': [
'css/univbris.css',
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class UnivbrisFoam (Plugin):
"""
if self.checkboxes:
# we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
if 'aoColumns' in self.datatables_options:
- print('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
+ logger.warning('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
del self.datatables_options['aoColumns']
# set aoColumnDefs in datatables_options - might already have stuff in there
aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class UnivbrisFv (Plugin):
"""
if self.checkboxes:
# we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
if 'aoColumns' in self.datatables_options:
- print('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
+ logger.warning('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
del self.datatables_options['aoColumns']
# set aoColumnDefs in datatables_options - might already have stuff in there
aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class UnivbrisTopo(Plugin):
def __init__ (self, query=None, **settings):
Plugin.__init__ (self, **settings)
self.query=query
self.query_uuid = query.query_uuid if query else None
- print("called univbris topo plugin")
+ logger.info("called univbris topo plugin")
def template_file (self):
try:
return "univbris_topology.html"
- except:
- print("error template")
+ except Exception as e :
+ logger.error("error template {}".format(e))
def requirements (self):
reqs = {
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class UnivbrisVtam (Plugin):
def __init__ (self, query=None, query_all=None, sync_query=None,
checkboxes=False, columns=None,
if self.checkboxes:
# we use aoColumnDefs rather than aoColumns -- ignore user-provided aoColumns
if 'aoColumns' in self.datatables_options:
- print('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
+ logger.warning('WARNING: querytable uses aoColumnDefs, your aoColumns spec. is discarded')
del self.datatables_options['aoColumns']
# set aoColumnDefs in datatables_options - might already have stuff in there
aoColumnDefs = self.datatables_options.setdefault ('aoColumnDefs',[])
-from __future__ import print_function
+#
+import json, os, re, itertools, time
+from OpenSSL import crypto
+from Crypto.PublicKey import RSA
-from unfold.loginrequired import LoginRequiredAutoLogoutView
#
+from django.http import HttpResponse, HttpResponseRedirect
+from django.contrib import messages
+from django.contrib.auth.decorators import login_required
+
#
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query
+
+from unfold.loginrequired import LoginRequiredAutoLogoutView
+from unfold.page import Page
+from ui.topmenu import topmenu_items_live, the_user
+
from portal.actions import (
manifold_update_user, manifold_update_account, manifold_add_account,
manifold_delete_account, sfa_update_user, sfa_get_user, clear_user_creds )
-#
-from unfold.page import Page
-from ui.topmenu import topmenu_items_live, the_user
-#
-from django.http import HttpResponse, HttpResponseRedirect
-from django.contrib import messages
-from django.contrib.auth.decorators import login_required
+from portal.account import Account, get_expiration
+from myslice.settings import logger
from myslice.configengine import ConfigEngine
-from myslice.theme import ThemeView
-
-from portal.account import Account, get_expiration
-#
-import json, os, re, itertools, time
-from OpenSSL import crypto
-from Crypto.PublicKey import RSA
+from myslice.theme import ThemeView
# requires login
class AccountView(LoginRequiredAutoLogoutView, ThemeView):
if user_email == request.user.email:
authorize_query = True
else:
- print("SECURITY: %s tried to update %s" % (user_email, request.user.email))
+ logger.error("SECURITY: {} tried to update {}".format(user_email, request.user.email))
messages.error(request, 'You are not authorized to modify another user.')
return HttpResponseRedirect("/portal/account/")
- except Exception,e:
- print("Exception = %s" % e)
+ except Exception as e:
+ logger.error("exception in account_process {}".format(e))
for account_detail in account_details:
for platform_detail in platform_details:
messages.success(request, 'Sucess: New Keypair Generated! Delegation of your credentials will be automatic.')
else:
raise Exception,"Keys are not matching"
- except Exception, e:
+ except Exception as e:
messages.error(request, 'Error: An error occured during the update of your public key at the Registry, or your public key is not matching the one stored.')
- print("Exception in accountview ", e)
+ logger.error("Exception in accountview {}".format(e))
return HttpResponseRedirect("/portal/account/")
else:
messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
messages.success(request, 'All Credentials cleared')
else:
messages.error(request, 'Delete error: Credentials are not stored in the server')
- except Exception,e:
- print("Exception in accountview.py in clear_user_creds %s" % e)
+ except Exception as e:
+ logger.error("Exception in accountview.py in clear_user_creds {}".format(e))
messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
return HttpResponseRedirect("/portal/account/")
-from __future__ import print_function
-
from django.http import HttpResponse
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query,execute_admin_query
from myslice.theme import ThemeView
from myslice.configengine import ConfigEngine
-
+from myslice.settings import logger
theme = ThemeView()
pi_status = True
return pi_status
- except Exception,e:
- print("Exception in actions.py in authority_check_pis %s" % e)
+ except Exception as e:
+ logger.error("Exception in actions.py in authority_check_pis {}".format(e))
return None
results = execute_query(request,query)
newpis = authority_get_pis (request, authority_hrn)
return newpis
- except Exception,e:
- print("Exception in actions.py in authority_add_pis %s" % e)
+ except Exception as e:
+ logger.error("Exception in actions.py in authority_add_pis {}".format(e))
return None
results = execute_query(request,query)
newpis = authority_get_pis (request, authority_hrn)
return newpis
- except Exception,e:
- print("Exception in actions.py in authority_remove_pis %s" % e)
+ except Exception as e:
+ logger.error("Exception in actions.py in authority_remove_pis {}".format(e))
return None
def authority_get_pi_emails(request, authority_hrn):
pi_users = authority_get_pis(request,authority_hrn)
- print("pi_users = %s" % pi_users)
+ logger.info("pi_users = %s" % pi_users)
if any(pi['pi_users'] == None or not pi['pi_users'] for pi in pi_users):
#theme.template_name = 'email_default_recipients.txt'
else:
return None
- except Exception,e:
- print("Exception in actions.py in clear_user_creds %s" % e)
+ except Exception as e:
+ logger.error("Exception in actions.py in clear_user_creds {}".format(e))
return None
def is_pi(wsgi_request, user_hrn, authority_hrn):
# authorities from user where user_hrn == "ple.upmc.jordan_auge"
- print("#### actions.py is_pi authority_hrn = ", authority_hrn)
+ logger.debug("#### actions.py is_pi authority_hrn = {}".format(authority_hrn))
try:
# CACHE PB with fields
page = Page(wsgi_request)
query = Query().get('myslice:user').select(user_fields).filter_by('user_hrn','==',user_hrn)
#query = Query.get('myslice:user').filter_by('user_hrn', '==', user_hrn).select('pi_authorities')
results = execute_query(wsgi_request, query)
- #print "is_pi results = ", results
for user_detail in results:
if authority_hrn in user_detail['pi_authorities']:
return True
- except Exception,e:
- print("Exception in actions.py in is_pi %s" % e)
+ except Exception as e:
+ logger.error("Exception in actions.py in is_pi {}".format(e))
return False
# SFA get record
# REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
query = Query.create('myslice:authority').set(authority_params).select('authority_hrn')
results = execute_query(request, query)
- print("sfa_add_auth results=",results)
+ logger.info("sfa_add_auth results={}".format(results))
if not results:
raise Exception, "Could not create %s. Already exists ?" % authority_params['hrn']
return results
return request
def make_requests(pending_users, pending_slices, pending_authorities, pending_projects, pending_joins):
- print("$$$$$$$$$$$$$$$ make_request")
+ logger.info("$$$$$$$$$$$$$$$ make_request")
requests = []
for user in pending_users:
requests.append(make_request_user(user))
return requests
def get_request_by_id(ids):
- print("$$$$$$$$$$$$$$$$ get_request_by_id")
+ logger.info("$$$$$$$$$$$$$$$$ get_request_by_id")
sorted_ids = { 'user': [], 'slice': [], 'authority': [], 'project': [], 'join': [] }
for type__id in ids:
type, id = type__id.split('__')
return make_requests(pending_users, pending_slices, pending_authorities, pending_projects, pending_joins)
def get_requests(authority_hrns=None):
- print("$$$$$$$$$$$$$ get_request_by_authority auth_hrns = ", authority_hrns)
+ logger.info("$$$$$$$$$$$$$ get_request_by_authority auth_hrns = {}".format(authority_hrns))
if not authority_hrns:
## get those pending users who have confirmed their emails
pending_users = PendingUser.objects.filter(status__iexact = 'True')
#'pi' : None,
#'enabled' : True
}
- print("ADD Authority")
+ logger.info("ADD Authority")
sfa_add_authority(wsgi_request, sfa_authority_params)
request_status['SFA authority'] = {'status': True }
PendingAuthority.objects.get(id=request['id']).delete()
msg = EmailMultiAlternatives(subject, text_content, sender, [user_email])
msg.attach_alternative(html_content, "text/html")
msg.send()
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
# removing from Django portal_pendinguser
PendingUser.objects.get(id=request['id']).delete()
msg = EmailMultiAlternatives(subject, text_content, sender, [user_email])
msg.attach_alternative(html_content, "text/html")
msg.send()
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
PendingSlice.objects.get(id=request['id']).delete()
msg = EmailMultiAlternatives(subject, text_content, sender, [user_email])
msg.attach_alternative(html_content, "text/html")
msg.send()
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
PendingAuthority.objects.get(id=request['id']).delete()
msg = EmailMultiAlternatives(subject, text_content, sender, [user_email])
msg.attach_alternative(html_content, "text/html")
msg.send()
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
return results
msg = EmailMultiAlternatives(subject, text_content, sender, recipients)
msg.attach_alternative(html_content, "text/html")
msg.send()
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
def create_pending_project(wsgi_request, request):
msg = EmailMultiAlternatives(subject, text_content, sender, [request['email']])
msg.attach_alternative(html_content, "text/html")
msg.send()
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
return results
iotlab_user_params1 = json.dumps(iotlab_user_params)
r=requests.post(url=URL_REST, data=iotlab_user_params1, headers=headers, auth=auth)
- print('Create iotlab user : ', r.status_code, r.text)
+ logger.info('Create iotlab user : {} {}'.format(r.status_code, r.text))
return r.text
def create_user(wsgi_request, request, namespace = None, as_admin = False):
'config' : json.dumps(account_config),
}
manifold_add_account(wsgi_request, account_params)
- except Exception, e:
- print("Failed creating manifold account on platform %s for user: %s" % ('myslice', request['email']))
+ except Exception as e:
+ logger.error("Failed creating manifold account on platform {} for user: {}".format('myslice', request['email']))
try:
# Send an email: the recipients are the PI of the authority
msg.attach_alternative(html_content, "text/html")
msg.send()
except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
import traceback
- traceback.print_exc()
+ logger.error(traceback.format_exc())
-from __future__ import print_function
-
import json
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query
from ui.topmenu import topmenu_items_live, the_user
-from myslice.theme import ThemeView
+from myslice.theme import ThemeView
+from myslice.settings import logger
+
#This view requires login
class DashboardView (LoginRequiredAutoLogoutView, ThemeView):
#messages.info(self.request, 'You have logged in')
page = Page(self.request)
- print("Dashboard page")
+ logger.info("Dashboard page")
# Slow...
#slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn')
testbed_query = Query().get('network').select('network_hrn','platform','version')
# root_authority = sub_authority[0]
# slice_query = Query().get(root_authority+':user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn')
# else:
- print("SLICE QUERY")
- print("-" * 80)
+ logger.debug("SLICE QUERY")
+ logger.debug("-" * 80)
slice_query = Query().get('myslice:user').filter_by('user_hrn', '==', '$user_hrn').select('slices.slice_hrn')
page.enqueue_query(slice_query)
page.enqueue_query(testbed_query)
-from __future__ import print_function
+import json
+import os
+import re
+import itertools
-from unfold.loginrequired import FreeAccessView
-#
-from manifold.core.query import Query
-from manifoldapi.manifoldapi import execute_query, execute_admin_query
-from portal.actions import manifold_update_user, manifold_update_account, manifold_add_account, manifold_delete_account, sfa_update_user, authority_get_pi_emails, make_request_user, create_user
-#
-from unfold.page import Page
-from ui.topmenu import topmenu_items_live, the_user
-#
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
-from myslice.theme import ThemeView
-from portal.models import PendingUser, PendingAuthority
from django.core.mail import EmailMultiAlternatives, send_mail
from django.contrib.sites.models import Site
-#
-import json, os, re, itertools
+from manifold.core.query import Query
+from manifoldapi.manifoldapi import execute_query, execute_admin_query
+
+from unfold.loginrequired import FreeAccessView
+
+from portal.actions import (
+ manifold_update_user, manifold_update_account, manifold_add_account,
+ manifold_delete_account, sfa_update_user, authority_get_pi_emails,
+ make_request_user, create_user)
+from portal.models import PendingUser, PendingAuthority
+
+from unfold.page import Page
+from ui.topmenu import topmenu_items_live, the_user
+
+from myslice.theme import ThemeView
+from myslice.settings import logger
+
def ValuesQuerySetToDict(vqs):
return [item for item in vqs]
# User is enabled in PLE
if 'enabled' in result and result['enabled']==True:
return True
- except Exception, e:
- print("Exception in myplc query = ",e)
+ except Exception as e:
+ logger.error("Exception in myplc query = {}".format(e))
return False
#page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] )
for key, value in kwargs.iteritems():
- #print "%s = %s" % (key, value)
if key == "hash_code":
hash_code=value
if PendingUser.objects.filter(email_hash__iexact = hash_code).filter(status__iexact = 'False'):
# msg = EmailMultiAlternatives(subject, text_content, sender, recipients)
# msg.attach_alternative(html_content, "text/html")
# msg.send()
- #except Exception, e:
- # print "Failed to send email, please check the mail templates and the SMTP configuration of your server"
+ #except Exception as e:
+ # logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
# import traceback
- # traceback.print_exc()
+ # logger.error(traceback.format_exc())
PendingUser.objects.filter(email_hash__iexact = hash_code).update(status='True')
else:
# this program; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-from __future__ import print_function
+# TODO: Remove these automated forms and use html templates and views like any other page !
from django import forms
-from portal.models import PendingUser, PendingSlice
#from crispy_forms.helper import FormHelper
#from crispy_forms.layout import Submit
from django.utils.translation import ugettext_lazy as _
from django.utils.http import int_to_base36
from django.template import loader
-# TODO: Remove these automated forms and use html templates and views like any other page !
from django.contrib.auth.hashers import identify_hasher
+
+from portal.models import PendingUser, PendingSlice
+
+from myslice.settings import logger
+
# adapted from https://sourcegraph.com/github.com/fusionbox/django-authtools/symbols/python/authtools/forms
def is_password_unusable(pw):
subject = ''.join(subject.splitlines())
email = loader.render_to_string(email_template_name, c)
send_mail(subject, email, from_email, [user.email])
- except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ except Exception as e:
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
class SetPasswordForm(forms.Form):
-from __future__ import print_function
+import time
+import json
# this somehow is not used anymore - should it not be ?
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from django.shortcuts import render
-
from unfold.loginrequired import FreeAccessView
+from ui.topmenu import topmenu_items, the_user
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query
-
from manifoldapi.manifoldresult import ManifoldResult
-from ui.topmenu import topmenu_items, the_user
-from myslice.configengine import ConfigEngine
+from myslice.configengine import ConfigEngine
from myslice.theme import ThemeView
+
from portal.account import Account, get_expiration
from portal.models import PendingSlice
from portal.actions import authority_check_pis
-import json, time
import activity.user
class HomeView (FreeAccessView, ThemeView):
-from __future__ import print_function
+import json
from django.core.context_processors import csrf
from django.http import HttpResponseRedirect
from portal.actions import is_pi, authority_check_pis
from myslice.theme import ThemeView
-import json
+from myslice.settings import logger
+
class InstitutionView (LoginRequiredAutoLogoutView, ThemeView):
template_name = 'institution.html'
else:
env['person'] = None
- print("BEFORE ####------#### is_pi")
+ logger.debug("BEFORE ####------#### is_pi")
pi = is_pi(self.request, '$user_hrn', env['user_details']['parent_authority'])
- print("is_pi = ",is_pi)
+ logger.debug("is_pi = {}".format(is_pi))
env['theme'] = self.theme
env['section'] = "Institution"
-from __future__ import print_function
-
import os.path, re
import json
from random import randint
from portal.actions import authority_get_pi_emails, manifold_add_user,manifold_add_account, create_pending_user
from myslice.theme import ThemeView
+from myslice.settings import logger
import activity.institution
msg.send()
except Exception, e:
- print("Failed to send email, please check the mail templates and the SMTP configuration of your server")
+ logger.error("Failed to send email, please check the mail templates and the SMTP configuration of your server")
import traceback
- traceback.print_exc()
+ logger.error(traceback.format_exc())
self.template_name = 'join_complete.html'
# log institution activity
-from __future__ import print_function
-
+import json
# this somehow is not used anymore - should it not be ?
from django.core.context_processors import csrf
from django.http import HttpResponseRedirect
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query
from manifoldapi.manifoldresult import ManifoldResult
-from myslice.configengine import ConfigEngine
+from myslice.configengine import ConfigEngine
from myslice.theme import ThemeView
-import json
+from myslice.settings import logger
class ManagementAboutView (FreeAccessView, ThemeView):
template_name = 'management-tab-about.html'
user_local_query = Query().get('local:user').select('config').filter_by('email','==',str(self.request.user))
user_local_details = execute_query(self.request, user_local_query)
user_authority = json.loads(user_local_details[0]['config']).get('authority')
- print("**************________ management about = ",user_authority)
+ logger.info("**************________ management about = {}".format(user_authority))
# XXX Should be done using Metadata
# select column.name from local:object where table=='authority'
authority_query = Query().get('authority').select('authority_hrn', 'name', 'address', 'enabled','description',
-from __future__ import print_function
+import json
from django.template import RequestContext
from django.shortcuts import render_to_response
from portal.actions import get_requests
from myslice.theme import ThemeView
-
-import json
+from myslice.settings import logger
class ManagementRequestsView (LoginRequiredView, ThemeView):
template_name = "management-tab-requests.html"
sfa_platforms_query = Query().get('local:platform').filter_by('gateway_type', '==', 'sfa').select('platform_id', 'platform', 'auth_type')
sfa_platforms = execute_query(self.request, sfa_platforms_query)
for sfa_platform in sfa_platforms:
- print("SFA PLATFORM > ", sfa_platform['platform'])
+ logger.info("SFA PLATFORM > {}".format(sfa_platform['platform']))
if not 'auth_type' in sfa_platform:
continue
auth = sfa_platform['auth_type']
all_authorities.append(auth)
platform_ids.append(sfa_platform['platform_id'])
- print("W: Hardcoding platform myslice")
+ logger.warning("W: Hardcoding platform myslice")
# There has been a tweak on how new platforms are referencing a
# so-called 'myslice' platform for storing authentication tokens.
# XXX This has to be removed in final versions.
try:
for pa in pi_authorities_tmp:
pi_authorities |= set(pa['pi_authorities'])
- except:
- print('No pi_authorities')
+ except Exception as e:
+ logger.error('No pi_authorities')
pi_credential_authorities = pi_authorities & credential_authorities
pi_no_credential_authorities = pi_authorities - credential_authorities - credential_authorities_expired
+import os
+import re
+import itertools
+import json
+
from unfold.loginrequired import LoginRequiredAutoLogoutView
-#
+
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query, execute_admin_query
from portal.actions import manifold_update_user, manifold_update_account, manifold_add_account, manifold_delete_account
-from portal.actions import sfa_update_user, authority_get_pis, authority_add_pis, authority_remove_pis,authority_check_pis ,clear_user_creds
-#
+from portal.actions import (
+ sfa_update_user, authority_get_pis, authority_add_pis,
+ authority_remove_pis,authority_check_pis ,clear_user_creds )
+
from unfold.page import Page
from ui.topmenu import topmenu_items_live, the_user
-#
+
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from myslice.theme import ThemeView
-#
-import json, os, re, itertools
# requires login
class UserView(LoginRequiredAutoLogoutView, ThemeView):
page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css","css/jquery-ui.css" ] )
for key, value in kwargs.iteritems():
- #print "%s = %s" % (key, value)
if key == "email":
selected_email=value
-from __future__ import print_function
-
from django.template import RequestContext
from django.shortcuts import render_to_response
from myslice.configengine import ConfigEngine
from myslice.theme import ThemeView
+from myslice.settings import logger
# View for 1 platform and its details
class PlatformView(FreeAccessView, ThemeView):
page.add_js_files ( [ "js/common.functions.js" ] )
for key, value in kwargs.iteritems():
- print("%s = %s" % (key, value))
+ logger.debug("{} = {}".format(key, value))
if key == "platformname":
platformname=value
-from __future__ import print_function
+import json
+import time
+import re
from django.shortcuts import render
from django.contrib.sites.models import Site
from portal.models import PendingProject, PendingJoin
from myslice.theme import ThemeView
-
-import json, time, re
+from myslice.settings import logger
class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
template_name = 'projectrequest_view.html'
errors.append('Project name is mandatory')
if not errors:
- print("is_pi on auth_hrn = ", user_authority)
+ logger.info("is_pi on auth_hrn = {}".format(user_authority))
if is_pi(wsgi_request, user_hrn, user_authority):
# PIs can directly create/join project in their own authority...
if 'join' in wsgi_request.POST:
-from __future__ import print_function
-
-import os.path, re
+import os.path
+import re
import json
from random import randint
from hashlib import md5
from portal.actions import create_pending_user
from myslice.theme import ThemeView
+from myslice.settings import logger
import activity.user
# REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
authorities_query = Query.get('authority').select('name', 'authority_hrn')
authorities = execute_admin_query(wsgi_request, authorities_query)
- print("RegistrationView authorities = ", authorities)
+ logger.info("RegistrationView authorities = {}".format(authorities))
if authorities is not None:
# Remove the root authority from the list
matching = [s for s in authorities if "." in s['authority_hrn']]
authorities = sorted(matching, key=lambda k: k['authority_hrn'])
authorities = sorted(matching, key=lambda k: k['name'])
- print("############ BREAKPOINT 1 #################")
+ logger.debug("############ BREAKPOINT 1 #################")
# Page rendering
page = Page(wsgi_request)
page.add_css_files ( [ "css/onelab.css", "css/registration.css", "css/jquery.qtip.min.css", "css/jquery.ui.combobox.css" ] )
page.expose_js_metadata()
- print("############ BREAKPOINT 2 #################")
+ logger.debug("############ BREAKPOINT 2 #################")
if method == 'POST':
reg_form = {}
# The form has been submitted
current_site = Site.objects.get_current()
current_site = current_site.domain
- print("############ BREAKPOINT 3 #################")
+ logger.debug("############ BREAKPOINT 3 #################")
post_email = wsgi_request.POST.get('email','').lower()
salt = randint(1,100000)
email_hash = md5(str(salt)+post_email).hexdigest()
'validation_link': current_site + '/portal/email_activation/'+ email_hash
}
- print("############ BREAKPOINT 4 #################")
+ logger.debug("############ BREAKPOINT 4 #################")
auth = wsgi_request.POST.get('org_name', None)
if auth is None or auth == "":
errors.append('Organization required: please select one or request its addition')
else:
- print("############ BREAKPOINT 5 #################")
+ logger.debug("############ BREAKPOINT 5 #################")
# Construct user_hrn from email (XXX Should use common code)
split_email = user_request['email'].split("@")[0]
return render(wsgi_request, self.template, {'theme': self.theme})
else:
- print("############ BREAKPOINT A #################")
+ logger.debug("############ BREAKPOINT A #################")
user_request = {}
## this is coming from onelab website onelab.eu
reg_form = {
}
# log user activity
activity.user.signup(self.request)
- print("############ BREAKPOINT B #################")
+ logger.debug("############ BREAKPOINT B #################")
template_env = {
#'topmenu_items': topmenu_items_live('Register', page),
template_env.update(user_request)
template_env.update(reg_form)
template_env.update(page.prelude_env ())
- print("############ BREAKPOINT C #################")
+ logger.debug("############ BREAKPOINT C #################")
return render(wsgi_request, self.template,template_env)
-from __future__ import print_function
-
from manifold.core.query import Query
from unfold.page import Page
page.add_js_files ( [ "js/common.functions.js" ] )
for key, value in kwargs.iteritems():
- print("%s = %s" % (key, value))
if key == "urn":
resource_urn=value
-from __future__ import print_function
+import json
+import time
+import re
from django.shortcuts import render
from django.contrib.sites.models import Site
-
from unfold.page import Page
from manifold.core.query import Query
from ui.topmenu import topmenu_items_live, the_user
from myslice.theme import ThemeView
-
-import json, time, re
+from myslice.settings import logger
import activity.user
# pi = "is_pi"
pi = authority_check_pis (wsgi_request, user_email)
- print("SLICEREQUESTVIEW.PY ----- pi=",pi)
+ logger.debug("SLICEREQUESTVIEW.PY ----- pi= {}".format(pi))
# Page rendering
page = Page(wsgi_request)
-from __future__ import print_function
+import json
from django.template import RequestContext
from django.shortcuts import render_to_response
+from django.views.generic.base import TemplateView
+from django.http import HttpResponse
+from django.shortcuts import render
from manifold.core.query import Query, AnalyzedQuery
from manifoldapi.manifoldapi import execute_query
-import json
-from django.views.generic.base import TemplateView
from unfold.loginrequired import LoginRequiredView
-from django.http import HttpResponse
-from django.shortcuts import render
-
from unfold.page import Page
from myslice.configengine import ConfigEngine
from plugins.univbrisfvf import UnivbrisFvf
from plugins.univbrisfvfo import UnivbrisFvfo
from plugins.univbristopo import UnivbrisTopo
-from plugins.univbrisvtam import UnivbrisVtam as UnivbrisVtamPlugin
+from plugins.univbrisvtam import UnivbrisVtam as UnivbrisVtamPlugin
from plugins.univbrisvtamform import UnivbrisVtamForm
from plugins.columns_editor import ColumnsEditor
from plugins.lists.simplelist import SimpleList
from myslice.theme import ThemeView
+from myslice.settings import logger
class SliceResourceView (LoginRequiredView, ThemeView):
template_name = "slice-resource-view.html"
slice_md = metadata.details_by_object('slice')
slice_fields = [column['name'] for column in slice_md['column']]
- print("SLICE RES VIEW fields = %s" % slice_fields)
+ logger.debug("SLICE RES VIEW fields = {}".format(slice_fields))
# TODO The query to run is embedded in the URL
# Example: select slice_hrn, resource.urn, lease.resource, lease.start_time, lease.end_time from slice where slice_hrn == "ple.upmc.myslicedemo"
main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
-from __future__ import print_function
-
# this somehow is not used anymore - should it not be ?
from django.core.context_processors import csrf
from django.http import HttpResponseRedirect
from myslice.theme import ThemeView
from myslice.configengine import ConfigEngine
+from myslice.settings import logger
from sfa.planetlab.plxrn import hash_loginbase
try:
for resources in current_resources:
list_res = resources['resource']
- #print "list_b4"
- #print list_res
for res in list_res:
split_list = res.split('+') # split the resource urn
- #print "list_after"
- #print split_list
if [s for s in split_list if 'ple' in s]: # find ple resources
res_hrn = split_list[-1] # last element is resource hrn
ple_resource_list.append(res_hrn)
nitos_resource_list.append(res_hrn)
- except Exception,e:
- print("Exception in slicetabexperiment.py in OneLab resource search %s" % e)
+ except Exception as e:
+ logger.error("Exception in slicetabexperiment.py in OneLab resource search {}".format(e))
- #print "list of ple res hrns"
- #print ple_resource_list
- #print "list of nit_paris res hrns"
- #print nitos_paris_resource_list
- #print "list of iotLab res hrns"
- #print iotlab_resource_list
- #print "list of nitos res hrns"
- #print nitos_resource_list
+ #logger.debug("list of ple res hrns")
+ #logger.debug(ple_resource_list)
+ #logger.debug("list of nit_paris res hrns")
+ #logger.debug(nitos_paris_resource_list)
+ #logger.debug("list of iotLab res hrns")
+ #logger.debug(iotlab_resource_list)
+ #logger.debug("list of nitos res hrns")
+ #logger.debug(nitos_resource_list)
all_users = list()
#get all iotlab users
res = urllib2.urlopen(req)
all_users = json.load(res)
except urllib2.URLError as e:
- print("There is a problem in getting iotlab users %s" % e.reason)
+ logger.error("There is a problem in getting iotlab users {}".format(e.reason))
#getting the login from email
def get_context_data(self, **kwargs):
page = Page(self.request)
- #print "UNIVBRIS page"
metadata = page.get_metadata()
page.expose_js_metadata()
# this program; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-from __future__ import print_function
-
import json
from django.http import HttpResponseRedirect, HttpResponse
from manifoldapi.manifoldapi import execute_query
from manifold.core.query import Query
from unfold.page import Page
+
from myslice.theme import ThemeView
+from myslice.settings import logger
class ValidatePendingView(LoginRequiredAutoLogoutView, ThemeView):
template_name = "validate_pending.html"
sfa_platforms_query = Query().get('local:platform').filter_by('gateway_type', '==', 'sfa').select('platform_id', 'platform', 'auth_type')
sfa_platforms = execute_query(self.request, sfa_platforms_query)
for sfa_platform in sfa_platforms:
- print("SFA PLATFORM > ", sfa_platform['platform'])
+ logger.info("SFA PLATFORM > {}".format(sfa_platform['platform']))
if not 'auth_type' in sfa_platform:
continue
auth = sfa_platform['auth_type']
all_authorities.append(auth)
platform_ids.append(sfa_platform['platform_id'])
- print("W: Hardcoding platform myslice")
+ logger.warning("W: Hardcoding platform myslice")
# There has been a tweak on how new platforms are referencing a
# so-called 'myslice' platform for storing authentication tokens.
# XXX This has to be removed in final versions.
#print "=" * 80
for user_account in user_accounts:
- print("USER ACCOUNT", user_account)
+ logger.debug("USER ACCOUNT {}".format(user_account))
if user_account['auth_type'] == 'reference':
continue # we hardcoded the myslice platform...
config = json.loads(user_account['config'])
creds = []
- print("CONFIG KEYS", config.keys())
+ logger.debug("CONFIG KEYS {}".format(config.keys()))
if 'authority_credentials' in config:
- print("***", config['authority_credentials'].keys())
+ logger.debug("*** AC {}".format(config['authority_credentials'].keys()))
for authority_hrn, credential in config['authority_credentials'].items():
#if credential is not expired:
credential_authorities.add(authority_hrn)
#else
# credential_authorities_expired.add(authority_hrn)
if 'delegated_authority_credentials' in config:
- print("***", config['delegated_authority_credentials'].keys())
+ logger.debug("*** DAC {}".format(config['delegated_authority_credentials'].keys()))
for authority_hrn, credential in config['delegated_authority_credentials'].items():
#if credential is not expired:
credential_authorities.add(authority_hrn)
#else
# credential_authorities_expired.add(authority_hrn)
- print('credential_authorities =', credential_authorities)
- print('credential_authorities_expired =', credential_authorities_expired)
+ logger.debug('credential_authorities = {}'.format(credential_authorities))
+ logger.debug('credential_authorities_expired = {}'.format(credential_authorities_expired))
# # Using cache manifold-tables to get the list of authorities faster
# all_authorities_query = Query.get('authority').select('name', 'authority_hrn')
try:
for pa in pi_authorities_tmp:
pi_authorities |= set(pa['pi_authorities'])
- except:
- print('No pi_authorities')
+ except Exception as e:
+ logger.error('No pi_authorities')
# TODO: exception if no parent_authority
# try:
# for pa in pi_authorities_tmp:
dest[auth_hrn].append(request)
context = super(ValidatePendingView, self).get_context_data(**kwargs)
- print("testing")
- print(ctx_my_authorities)
+ logger.debug("testing")
+ logger.debug(ctx_my_authorities)
context['my_authorities'] = ctx_my_authorities
context['sub_authorities'] = ctx_sub_authorities
context['delegation_authorities'] = ctx_delegation_authorities
-from __future__ import print_function
+import decimal
+import datetime
+import json
+
+from django.http import HttpResponse
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query
-from portal.actions import is_pi
-
-from django.http import HttpResponse
+from portal.actions import is_pi
-import decimal
-import datetime
-import json
+from myslice.settings import logger
# handles serialization of datetime in json
DateEncoder = lambda obj: obj.strftime("%B %d, %Y %H:%M:%S") if isinstance(obj, datetime.datetime) else None
# What about key formed of multiple fields???
query = Query.get('local:object').filter_by('table', '==', self.type).select('key')
results = execute_query(self.request, query)
- print("key of object = %s" % results)
+ logger.debug("key of object = {}".format(results))
if results :
for r in results[0]['key'] :
self.id = r
if self.params :
for p in self.params :
for k,v in p.iteritems() :
- print("param: %s : %s" % (k,v))
+ logger.debug("param: {} : {}".format(k, v))
query.set({k : v})
- print("query = ",query)
+ logger.debug("query = {}".format(query))
else:
raise Exception, "Params are required for create"
return execute_query(self.request, query)
if self.params :
for p in self.params :
for k,v in p.iteritems() :
- print("param: %s : %s" % (k,v))
+ logger.debug("param: {} : {}".format(k, v))
query.set({k : v})
- print("query = ",query)
+ logger.debug("query = {}".format(query))
else:
raise Exception, "Params are required for update"
-from __future__ import print_function
-
from django.views.generic.base import TemplateView
from django.shortcuts import render_to_response
elif request.method == 'GET':
#return error('only post request is supported')
req_items = request.GET
- print(req_items)
for el in list(req_items.items()):
# Filters not used for create
if el[0].startswith('filters'):
-from __future__ import print_function
-
from django.shortcuts import render_to_response
from unfold.loginrequired import LoginRequiredView
if el[0].startswith('filters'):
o.filters[el[0][8:-1]] = el[1]
elif el[0].startswith('fields'):
- print(req_items.getlist('fields[]'))
o.setFields(req_items.getlist('fields[]'))
elif el[0].startswith('options'):
o.options = req_items.getlist('options[]')
error = "Error in delete return value"
except Exception, e:
error = str(e)
- #print "Exception : ",e
if error is not None:
ret = { "ret" : 1, "error" : error }
elif not results :
-from __future__ import print_function
+import os
+import json
+import ConfigParser
+
+from django.shortcuts import render_to_response
+from django.http import HttpResponse
from sfa.trust.certificate import Keypair, Certificate
from sfa.client.sfaserverproxy import SfaServerProxy
from sfa.client.return_value import ReturnValue
from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn
+
from manifold.core.query import Query
from manifold.models import db
from manifold.models.platform import Platform
from manifold.models.user import User
-from django.shortcuts import render_to_response
-
from unfold.loginrequired import LoginRequiredView
-from rest import ObjectRequest, error
-
-from string import join
-
-from django.http import HttpResponse
-from rest import error
-import os,json
-
-import ConfigParser
+from myslice.settings import logger
def dispatch(request, method):
Config = ConfigParser.ConfigParser()
from manifoldapi.manifoldapi import execute_admin_query
for pf in platforms:
platform = get_platform_config(pf)
- print(platform)
+ logger.debug("platform={}".format(platform))
if 'sm' in platform and len(platform['sm']) > 0:
- print('sm')
+ logger.debug('sm')
server_url = platform['sm']
if 'rm' in platform and len(platform['rm']) > 0:
- print('rm')
+ logger.debug('rm')
server_url = platform['rm']
if 'registry' in platform and len(platform['registry']) > 0:
- print('registry')
+ logger.debug('registry')
server_url = platform['registry']
if not Config.has_option('monitor', 'cert') :
-from __future__ import print_function
+from rest import ObjectRequest, error, success
from django.views.generic.base import TemplateView
from django.shortcuts import render_to_response
+from django.http import HttpResponse
from unfold.loginrequired import LoginRequiredView
-from django.http import HttpResponse
from manifold.core.query import Query, AnalyzedQuery
from manifoldapi.manifoldapi import execute_query
-from rest import ObjectRequest, error, success
-
-from string import join
-
-import json
-
+from myslice.settings import logger
def dispatch(request, object_type, object_name):
elif request.method == 'GET':
#return error('only post request is supported')
req_items = request.GET
- print(req_items)
+ logger.debug(req_items)
for el in req_items.items():
- print("#===============>",el)
+ logger.debug("#===============> {}".format(el))
if el[0].startswith('filters'):
o.filters[el[0][8:-1]] = el[1]
elif el[0].startswith('params'):
- print("#======> 0 ", el[0])
- print("#======> 1 ", req_items.getlist(el[0]))
+ logger.debug("#======> 0 {}".format(el[0]))
+ logger.debug("#======> 1 {}".format(req_items.getlist(el[0])))
if (el[0][-2:] == '[]') :
# when receiving params[key][] = 'value1' ...
# when receiving params[key] = 'value'
o.params.append({el[0][7:-1]:el[1]})
- print("o.params = ",o.params)
+ logger.debug("o.params = {}".format(o.params))
elif el[0].startswith('fields'):
o.fields=req_items.getlist('fields[]')
# tmp
from trashutils import lorem, hard_wired_slice_names
+from myslice.settings import logger
+
@login_required
def tab_view (request):
- print "request", request.__class__
- print request
+ logger.info("request {}".format(request.__class__))
+ logger.info("{}".format(request))
prelude=Prelude( js_files='js/bootstrap.js', css_files='css/bootstrap.css')
tab_env = {'title':'Page for playing with Tabs',
from ui.topmenu import topmenu_items_live, the_user
+from myslice.settings import logger
+
class TopmenuValidationView (TemplateView):
# mention a user name in the URL as .../trash/simpletopmenuvalidation/ple.inria.thierry_parmentelat
# define {js,css}_{files,chunks}
prelude_env = page.prelude_env()
-# print prelude_env.keys()
+# logger.info(prelude_env.keys())
# for k in [ 'js_files' ] :
-# print 'prelude_env',prelude_env,k,prelude_env[k]
+# logger.info('prelude_env {} {} {}'.format(prelude_env,k,prelude_env[k]))
template_env.update(prelude_env)
result=render_to_response ('view-unfold1.html',template_env,
# a set of utilities to help make the global layout consistent across views
+from myslice.settings import logger
+
def the_user (request):
"retrieves logged in user's email, or empty string"
if not request.user.is_authenticated ():
def topmenu_items_static (current, request):
has_user=request.user.is_authenticated()
result=[]
- print request.user
+ logger.debug("request user = {}".format(request.user))
if has_user:
result.append({'label':'Dashboard', 'href': '/portal/dashboard/'})
result.append({'label':'Request a slice', 'href': '/portal/slice_request/'})
# tmp - transition phase
def topmenu_items (current, request):
- print "WARNING -- please now use topmenu_items_live (label, page) toplevel_items is deprecated -- WARNING"
+ logger.warning("WARNING -- please now use topmenu_items_live (label, page) toplevel_items is deprecated -- WARNING")
return topmenu_items_static (current, request)
# integrated helper function for an animated menu
-from __future__ import print_function
-
from unfold.plugin import Plugin
+from myslice.settings import logger
+
class Composite (Plugin):
"""a simple base class for plugins that contain/arrange a set of other plugins
def __init__ (self, sons=None, active_domid=None, *args, **kwds):
Plugin.__init__ (self, *args, **kwds)
- self.sons= sons if sons else []
- self.active_domid=active_domid
+ self.sons = sons if sons else []
+ self.active_domid = active_domid
# make sure this is valid, unset otherwise, so we always have exactly one active
self.check_active_domid()
def check_active_domid(self):
matches= [ son for son in self.sons if son.domid==self.active_domid ]
if len(matches)!=1:
- print("WARNING: %s has %d valid son(s) for being active - expecting 1, resetting"%\
- (self,len(matches)))
- self.active_domid=None
+ logger.warning("WARNING: {} has {} valid son(s) for being active - expecting 1, resetting"\
+ .format(self,len(matches)))
+ self.active_domid = None
def insert (self, plugin):
self.sons.append(plugin)
# {% for son in sons %} {{ son.rendered }} ...
def is_active (son,rank):
# if active_domid is not specified, make the first one active
- if not self.active_domid: return rank==0
- return son.domid==self.active_domid
- ranks=range(len(self.sons))
+ if not self.active_domid:
+ return rank==0
+ return son.domid == self.active_domid
+ ranks = range(len(self.sons))
env = { 'sons':
[ { 'rendered': son.render(request),
'rank': rank,
-from __future__ import print_function
-
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.http import HttpResponseRedirect
from manifoldapi.manifoldresult import ManifoldException
+from myslice.settings import logger
+
###
# IMPORTANT NOTE
# the implementation of the classes in this file rely on redefining 'dispatch'
def logout_on_manifold_exception (fun_that_returns_httpresponse):
def wrapped (request, *args, **kwds):
-# print 'wrapped by logout_on_manifold_exception'
try:
return fun_that_returns_httpresponse(request,*args, **kwds)
except ManifoldException, manifold_result:
return HttpResponseRedirect ('/')
except Exception, e:
# xxx we need to sugarcoat this error message in some error template...
- print("Unexpected exception",e)
+ logger.error("Unexpected exception {}".format(e))
import traceback
- traceback.print_exc()
+ logger.error(traceback.format_exc())
return HttpResponseRedirect ('/')
return wrapped
-from __future__ import print_function
-
# the supervisor for Plugins
# keeps a handle on all present plugins for managing their queries in a consistent way
# it is expected to exist one such object for a given page
from unfold.prelude import Prelude
from myslice.configengine import ConfigEngine
+from myslice.settings import logger
# decorator to deflect calls on this Page to its prelude
def to_prelude (method):
# if cached, use it
if 'metadata' in manifold and isinstance(manifold['metadata'],MetaData):
- if debug: print("Page.get_metadata: return cached value")
+ logger.debug("Page.get_metadata: return cached value")
return manifold['metadata']
metadata_auth = {'AuthMethod':'anonymous'}
metadata.fetch(self.request)
# store it for next time
manifold['metadata']=metadata
- if debug: print("Page.get_metadata: return new value")
+ logger.debug("Page.get_metadata: return new value")
return metadata
def expose_js_metadata (self):
# so it should be specialized in real plugin classes
# like e.g. plugins.simplelist.SimpleList
-from __future__ import print_function
-
import json
from django.template.loader import render_to_string
from unfold.page import Page
from unfold.prelude import Prelude
+from myslice.settings import logger
+
####################
# set DEBUG to
# . False : silent
# . [ 'SliceList', 'TabbedView' ] : to debug these classes
# . True : to debug all plugin
-DEBUG= False
-#DEBUG= [ 'SimpleList' ]
-#DEBUG=True
+DEBUG = False
+#DEBUG = [ 'SimpleList' ]
+#DEBUG = True
# decorator to deflect calls on Plugin to its Prelude through self.page.prelude
def to_prelude (method):
def actual (self, *args, **kwds):
if not self.page: # jordan
return None
- prelude_method=Prelude.__dict__[method.__name__]
- return prelude_method(self.page.prelude,*args, **kwds)
+ prelude_method = Prelude.__dict__[method.__name__]
+ return prelude_method(self.page.prelude, *args, **kwds)
return actual
class Plugin:
# using a simple incremental scheme to generate domids for now
# we just need this to be unique in a page
- domid=0
+ domid = 0
# when a domid is not set by the caller, we name plugins after their respective class as well,
# so as to limit name clashes between different views
# and maybe xxx we should just enforce that...
def newdomid(self):
Plugin.domid += 1
- return "plugin-%s-%d"%(self.__class__.__name__.lower(),Plugin.domid)
+ return "plugin-{}-{}".format(self.__class__.__name__.lower(), Plugin.domid)
##########
# Constructor
**settings):
self.page = page
# callers can provide their domid for css'ing
- if not domid: domid=self.newdomid()
- self.domid=domid
+ if not domid:
+ domid=self.newdomid()
+ self.domid = domid
# title is shown when togglable
#if not title: title="Plugin title for %s"%domid
- self.title=title
- self.classname=self._py_classname()
- self.plugin_classname=self._js_classname()
- self.visible=visible
- if togglable is None: self.togglable=self.default_togglable()
- else: self.togglable=togglable
- if toggled is None: self.toggled=self.default_toggled()
- else: self.toggled=toggled
- if outline_complete is None: self.outline_complete=self.default_outline_complete()
- else: self.outline_complete=outline_complete
- if outline_body is None: self.outline_body=self.default_outline_body()
- else: self.outline_body=outline_body
+ self.title = title
+ self.classname = self._py_classname()
+ self.plugin_classname = self._js_classname()
+ self.visible = visible
+ if togglable is None: self.togglable = self.default_togglable()
+ else: self.togglable = togglable
+ if toggled is None: self.toggled = self.default_toggled()
+ else: self.toggled = toggled
+ if outline_complete is None: self.outline_complete = self.default_outline_complete()
+ else: self.outline_complete = outline_complete
+ if outline_body is None: self.outline_body = self.default_outline_body()
+ else: self.outline_body = outline_body
# what comes from subclasses
for (k,v) in settings.iteritems():
- setattr(self,k,v)
- if self.need_debug(): print("%s init - subclass setting %s"%(self.classname,k))
+ setattr(self, k, v)
+ if self.need_debug():
+ logger.debug("{} init - subclass setting {}".format(self.classname, k))
# minimal debugging
if self.need_debug():
- print("%s init dbg .... BEG"%self.classname)
- for (k,v) in self.__dict__.items(): print("dbg %s:%s"%(k,v))
- print("%s init dbg .... END"%self.classname)
+ logger.debug("{} init dbg .... BEG".format(self.classname))
+ for (k, v) in self.__dict__.items():
+ logger.debug("dbg {}:{}".format(k, v))
+ logger.debug("{} init dbg .... END".format(self.classname))
# do this only once the structure is fine
if self.page: # I assume we can have a None page (Jordan)
self.page.record_plugin(self)
def setting_json (self, setting):
# TMP: js world expects plugin_uuid
- if setting=='plugin_uuid':
- value=self.domid
- elif setting=='query_uuid':
- try: value=self.query.query_uuid
- except: return '%s:"undefined"'%setting
+ if setting == 'plugin_uuid':
+ value = self.domid
+ elif setting == 'query_uuid':
+ try: value = self.query.query_uuid
+ except: return '{}:"undefined"'.format(setting)
else:
- value=getattr(self,setting,None)
- if value is None: value = "unknown-setting-%s"%setting
+ value = getattr(self,setting,None)
+ if value is None:
+ value = "unknown-setting-%s"%setting
# first try to use to_json method (json.dumps not working on class instances)
- try: value_json=value.to_json()
- except: value_json=json.dumps(value,separators=(',',':'))
- return "%s:%s"%(setting,value_json)
+ try: value_json = value.to_json()
+ except: value_json = json.dumps(value,separators=(',',':'))
+ return "{}:{}".format(setting, value_json)
# expose in json format to js the list of fields as described in json_settings_list()
# and add plugin_uuid: domid in the mix
def settings_json (self):
exposed_settings=self.json_settings_list()
if 'query' in exposed_settings:
- print("WARNING, cannot expose 'query' directly in json_settings_list, query_uuid is enough")
+ logger.debug("WARNING, cannot expose 'query' directly in json_settings_list, query_uuid is enough")
result = "{"
result += ",".join([ self.setting_json(setting) for setting in self.json_settings_list() ])
result += "}"
plugin_content = self.render_content (request)
# shove this into plugin.html
env = {}
- env ['plugin_content']= plugin_content
+ env['plugin_content'] = plugin_content
env.update(self.__dict__)
# translate high-level 'toggled' into 4 different booleans
self.need_toggle = False
- if self.toggled=='persistent':
+ if self.toggled == 'persistent':
# start with everything turned off and let the js callback do its job
- env.update({'persistent_toggle':True,'display_hide_button':False,
- 'display_show_button':False,'display_body':False})
- elif self.toggled==False:
- env.update({'persistent_toggle':False,'display_hide_button':False,
- 'display_show_button':True,'display_body':False})
+ env.update({'persistent_toggle' : True, 'display_hide_button' : False,
+ 'display_show_button' : False, 'display_body' : False})
+ elif self.toggled == False:
+ env.update({'persistent_toggle' : False, 'display_hide_button' : False,
+ 'display_show_button' : True, 'display_body' : False})
else:
- env.update({'persistent_toggle':False,'display_hide_button':True,
- 'display_show_button':False,'display_body':True})
+ env.update({'persistent_toggle' : False, 'display_hide_button' : True,
+ 'display_show_button' : False, 'display_body' : True})
if self.need_debug():
- print("rendering plugin.html with env keys %s"%env.keys())
+ logger.debug("rendering plugin.html with env keys {}".format(env.keys()))
for (k,v) in env.items():
- if "display" in k or "persistent" in k: print(k,'->',v)
+ if "display" in k or "persistent" in k:
+ logger.debug("{} -> {}".format(k, v))
result = render_to_string ('plugin.html',env)
# export this only for relevant plugins
"""Should return an HTML fragment"""
template = self.template_file()
# start with a fresh one
- env={}
+ env = {}
# add our own settings as defaults
env.update(self.__dict__)
# then the things explicitly defined in template_env()
env.update(self.template_env(request))
if not isinstance (env,dict):
raise Exception, "%s.template_env returns wrong type"%self.classname
- result=render_to_string (template, env)
+ result = render_to_string (template, env)
if self.need_debug():
- print("%s.render_content: BEG --------------------"%self.classname)
- print("template=%s"%template)
- print("env.keys=%s"%env.keys())
- #print "env=%s"%env
- #print result
- print("%s.render_content: END --------------------"%self.classname)
+ logger.debug("{}.render_content: BEG --------------------".format(self.classname))
+ logger.debug("template={}".format(template))
+ logger.debug("env.keys={}".format(env.keys()))
+ logger.debug("{}.render_content: END --------------------".format(self.classname))
return result
# or from the result of self.requirements()
def handle_requirements (self, request):
try:
- d=self.requirements()
+ d = self.requirements()
for (k,v) in d.iteritems():
if self.need_debug():
- print("%s: handling requirement %s"%(self.classname,v))
+ logger.debug("{}: handling requirement {}".format(self.classname, v))
# e.g. js_files -> add_js_files
- method_name='add_'+k
- method=Page.__dict__[method_name]
- method(self.page,v)
+ method_name = 'add_' + k
+ method = Page.__dict__[method_name]
+ method(self.page, v)
except AttributeError:
# most likely the object does not have that method defined, which is fine
pass
except:
import traceback
- traceback.print_exc()
+ logger.log(traceback.format_exc())
pass
#################### requirements/prelude management
-from __future__ import print_function
-
from types import StringTypes, ListType
from django.template.loader import render_to_string
+from myslice.settings import logger
+
debug=False
# the need for js_init_chunks is because we need to have the plugins initialized
result += ",".join( [ "%s->%s"%(k,len(getattr(self,k))) for k in Prelude.keys ] )
return result
def inspect (self,msg):
- print(self.inspect_string(msg))
+ logger.debug(self.inspect_string(msg))
# first attempt was to use a simple dict like this
# env={}
env['all_js_chunks']= self.js_init_chunks + self.js_chunks
env['css_chunks']=self.css_chunks
if debug:
- print("prelude has %d js_files, %d css files, (%d+%d) js chunks and %d css_chunks"%\
- (len(self.js_files),len(self.css_files),len(self.js_init_chunks),len(self.js_chunks),len(self.css_chunks),))
+ logger.debug("prelude has {} js_files, {} css files, ({}+{}) js chunks and {} css_chunks"\
+ .format (len(self.js_files), len(self.css_files),
+ len(self.js_init_chunks), len(self.js_chunks), len(self.css_chunks),))
# render this with prelude.html and put the result in header_prelude
header_prelude = render_to_string ('prelude.html',env)
return { 'header_prelude' : header_prelude }