Skip to content

Commit

Permalink
PEP8 Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
struegamer committed Mar 23, 2014
1 parent 48c9292 commit 2116caa
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 125 deletions.
29 changes: 14 additions & 15 deletions components/dc2-appserver/dc2/appserver/auth/__init__.py
@@ -1,19 +1,18 @@
# -*- coding: utf-8 -*-
#################################################################################
#
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
#
# 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.
#################################################################################
29 changes: 14 additions & 15 deletions components/dc2-appserver/dc2/appserver/auth/rpcmethods/__init__.py
@@ -1,19 +1,18 @@
# -*- coding: utf-8 -*-
#################################################################################
#
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
#
# 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.
#################################################################################
118 changes: 71 additions & 47 deletions components/dc2-appserver/dc2/appserver/auth/rpcmethods/groups.py
@@ -1,37 +1,27 @@
# -*- coding: utf-8 -*-
#################################################################################
#
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
#
# 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.
#################################################################################

import sys
import types
import xmlrpclib
import re
import uuid

try:
import web
except ImportError:
print "You don't have web.py installed"
sys.exit(1)

try:
from dc2.lib.db.mongo import Database
from dc2.lib.db.mongo import Table
from dc2.appserver.helpers import check_record
from dc2.appserver.rpc import rpcmethod
Expand All @@ -45,53 +35,87 @@
print "You don't have a settings file"
sys.exit(1)

tbl_groups=Table(MONGOS["userdb"]["database"].get_table("groups"))
tbl_groups = Table(MONGOS["userdb"]["database"].get_table("groups"))

GROUP_RECORD={
"groupname":True,
"description":True,
"users":False,
GROUP_RECORD = {
"groupname": True,
"description": True,
"users": False,
}

@rpcmethod(name="dc2.configuration.groups.list",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
name="dc2.configuration.groups.list",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_groups_list(search=None):
if search is not None and type(search) is types.DictType:
if search is not None and isinstance(search, dict):
for k in search.keys():
a = re.compile('%s' % search[k], re.IGNORECASE)
search[k] = a
result = tbl_groups.find(search)
else:
result = tbl_groups.find();
result = tbl_groups.find()
return result

@rpcmethod(name="dc2.configuration.groups.add",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
name="dc2.configuration.groups.add",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_groups_add(record=None):
if record is not None and type(record) is types.DictType:
if check_record(record,GROUP_RECORD) and tbl_groups.find_one({"groupname":record["groupname"]}) is None:
doc_id=tbl_groups.save(record)
if record is not None and isinstance(record, dict):
if (check_record(record, GROUP_RECORD) and
tbl_groups.find_one(
{"groupname": record["groupname"]}) is None):
doc_id = tbl_groups.save(record)
return doc_id
return xmlrpclib.Fault(-32501, "Record couldn't be added")

@rpcmethod(name="dc2.configuration.groups.update",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
name="dc2.configuration.groups.update",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_groups_update(record=None):
if record is not None and type(record) is types.DictType:
if check_record(record,GROUP_RECORD) and tbl_groups.find_one({"groupname":record["groupname"]}) is not None:
doc_id=tbl_groups.save(record)
if record is not None and isinstance(record, dict):
if (check_record(record, GROUP_RECORD) and
tbl_groups.find_one(
{"groupname": record["groupname"]}) is not None):
doc_id = tbl_groups.save(record)
return doc_id
return xmlrpclib.Fault(-32501, "Record couldn't be updated")

@rpcmethod(name="dc2.configuration.groups.delete",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
name="dc2.configuration.groups.delete",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_groups_delete(record=None):
if record is not None and type(record) is types.DictType:
if record.has_key("_id") or record.has_key("groupname"):
if record is not None and isinstance(record, dict):
if '_id' in record or 'groupname' in record:
tbl_groups.remove(record)
return True
return False

@rpcmethod(name="dc2.configuration.groups.get",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
name="dc2.configuration.groups.get",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_groups_get(record=None):
if record is not None and type(record) is types.DictType:
if record.has_key("_id") or record.has_key("groupname"):
user_rec=tbl_groups.find_one(record)
if record is not None and isinstance(record, dict):
if '_id' in record or 'groupname' in record:
user_rec = tbl_groups.find_one(record)
return user_rec
return None
119 changes: 71 additions & 48 deletions components/dc2-appserver/dc2/appserver/auth/rpcmethods/users.py
@@ -1,37 +1,28 @@
# -*- coding: utf-8 -*-
#################################################################################
#
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
#
# 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.
#################################################################################

import sys
import types
import xmlrpclib
import re
import uuid

try:
import web
except ImportError:
print "You don't have web.py installed"
sys.exit(1)

try:
from dc2.lib.db.mongo import Database
from dc2.lib.db.mongo import Table
from dc2.appserver.helpers import check_record
from dc2.appserver.rpc import rpcmethod
Expand All @@ -46,55 +37,87 @@
sys.exit(1)


tbl_users=Table(MONGOS["userdb"]["database"].get_table("users"))
tbl_users = Table(MONGOS["userdb"]["database"].get_table("users"))

USER_RECORD={
"username":True,
"password":True,
"name":True,
USER_RECORD = {
"username": True,
"password": True,
"name": True,
}

@rpcmethod("dc2.configuration.users.list",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
"dc2.configuration.users.list",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_users_list(search=None):
if search is not None and type(search) is types.DictType:
if search is not None and isinstance(search, dict):
for k in search.keys():
a = re.compile('%s' % search[k], re.IGNORECASE)
a = re.compile('{0}'.format(search[k]), re.IGNORECASE)
search[k] = a
result = tbl_users.find(search)
else:
result = tbl_users.find();
result = tbl_users.find()
return result

@rpcmethod("dc2.configuration.users.add",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
"dc2.configuration.users.add",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_users_add(record=None):
if record is not None and type(record) is types.DictType:
if check_record(record,USER_RECORD) and tbl_users.find_one({"username":record["username"]}) is None:
doc_id=tbl_users.save(record)
if record is not None and isinstance(record, dict):
if (check_record(record, USER_RECORD) and
tbl_users.find_one(
{"username": record["username"]}) is None):
doc_id = tbl_users.save(record)
return doc_id
return xmlrpclib.Fault(-32501, "Record couldn't be added")

@rpcmethod("dc2.configuration.users.update",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
"dc2.configuration.users.update",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_users_update(record=None):
if record is not None and type(record) is types.DictType:
if check_record(record,USER_RECORD) and tbl_users.find_one({"username":record["useranme"]}) is not None:
doc_id=tbl_users.save(record)
if record is not None and isinstance(record, dict):
if (check_record(record, USER_RECORD) and
tbl_users.find_one(
{"username": record["useranme"]}) is not None):
doc_id = tbl_users.save(record)
return doc_id
return xmlrpclib.Fault(-32501, "Record couldn't be updated")

@rpcmethod("dc2.configuration.users.delete",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)

@rpcmethod(
"dc2.configuration.users.delete",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_users_delete(record=None):
if record is not None and type(record) is types.DictType:
if record.has_key("_id") or record.has_key("username"):
if record is not None and isinstance(record, dict):
if '_id' in record or 'username' in record:
tbl_users.remove(record)
return True
return False


@rpcmethod("dc2.configuration.users.get",params={},returns={},is_xmlrpc=True,is_jsonrpc=True)
@rpcmethod(
"dc2.configuration.users.get",
params={},
returns={},
is_xmlrpc=True,
is_jsonrpc=True)
def dc2_authentication_users_get(record=None):
if record is not None and type(record) is types.DictType:
if record.has_key("_id") or record.has_key("username"):
user_rec=tbl_users.find_one(record)
if record is not None and isinstance(record, dict):
if '_id' in record or 'username' in record:
user_rec = tbl_users.find_one(record)
return user_rec
return None

0 comments on commit 2116caa

Please sign in to comment.