diff options
-rw-r--r-- | gstudio/management/commands/sync-gbobjects.py | 71 | ||||
-rw-r--r-- | gstudio/xmlrpc/__init__.py | 8 | ||||
-rw-r--r-- | gstudio/xmlrpc/metaweblog.py | 65 |
3 files changed, 88 insertions, 56 deletions
diff --git a/gstudio/management/commands/sync-gbobjects.py b/gstudio/management/commands/sync-gbobjects.py new file mode 100644 index 00000000..faf4274b --- /dev/null +++ b/gstudio/management/commands/sync-gbobjects.py @@ -0,0 +1,71 @@ +# Copyright (c) 2012 Free Software Foundation + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from django.core.management.base import BaseCommand +from optparse import make_option + +import re +from datetime import datetime +from objectapp.models import Gbobject +from xmlrpclib import DateTime +from xmlrpclib import ServerProxy + +class Command(BaseCommand): + """Gets all Gbobjects for a specified server""" + option_list = BaseCommand.option_list + ( + make_option("--server", action="store", type="string", + dest="server", help="Specify an ip"),) + + def handle(self, *args, **options): + def parse_id(id=None): + def inner_parse(id): + """Gets a dict, parses and saves it""" + dict = srv.metaWeblog.dict_id(id) + pattern = "^(\d{4})(\d{2})(\d{2}).(\d{2}).(\d{2}).(\d{2})$" + + cd = DateTime().make_comparable(dict['creation_date'])[1] + lu = DateTime().make_comparable(dict['last_update'])[1] + ep = DateTime().make_comparable(dict['end_publication'])[1] + sp = DateTime().make_comparable(dict['start_publication'])[1] + + def group(value): + return value.group(1, 2, 3, 4, 5, 6) + + cd = group(re.search(pattern, cd)) + lu = group(re.search(pattern, lu)) + ep = group(re.search(pattern, ep)) + sp = group(re.search(pattern, sp)) + + def str_to_int(string): + return [int(x) for x in string] + + cd = str_to_int(cd) + lu = str_to_int(lu) + ep = str_to_int(ep) + sp = str_to_int(sp) + + dict['creation_date'] = datetime(*cd) + dict['last_update'] = datetime(*lu) + dict['end_publication'] = datetime(*ep) + dict['start_publication'] = datetime(*sp) + + Gbobject(**dict).save() + + for d in srv.metaWeblog.dict_id(): + inner_parse(d['node_ptr_id']) + + server = options["server"] + srv = ServerProxy(server, allow_none=True) + parse_id() diff --git a/gstudio/xmlrpc/__init__.py b/gstudio/xmlrpc/__init__.py index 9dd4ca22..9b91635d 100644 --- a/gstudio/xmlrpc/__init__.py +++ b/gstudio/xmlrpc/__init__.py @@ -125,9 +125,11 @@ GSTUDIO_XMLRPC_METAWEBLOG = [ ('gstudio.xmlrpc.metaweblog.set_relation', 'metaWeblog.setRelation'), ('gstudio.xmlrpc.metaweblog.get_gbobject_neighbourhood', - 'metaWeblog.getGbobjectNeighbourhood') - -] + 'metaWeblog.getGbobjectNeighbourhood'), + ('gstudio.xmlrpc.metaweblog.list_id', + 'metaWeblog.list_id'), + ('gstudio.xmlrpc.metaweblog.dict_id', + 'metaWeblog.dict_id')] GSTUDIO_XMLRPC_METHODS = GSTUDIO_XMLRPC_PINGBACK + GSTUDIO_XMLRPC_METAWEBLOG diff --git a/gstudio/xmlrpc/metaweblog.py b/gstudio/xmlrpc/metaweblog.py index 6990ca12..a77ab82a 100644 --- a/gstudio/xmlrpc/metaweblog.py +++ b/gstudio/xmlrpc/metaweblog.py @@ -831,58 +831,17 @@ def set_relation(d,obj1,obj2) : s.save() return s.id except Relationtype.DoesNotExist : - return "Relationtype Does Not Exist" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + return "Relationtype Does Not Exist" +@xmlrpc_func(returns='list') +def list_id(): + """Get a list of Gbobjects' ids""" + return [id.id for id in Gbobject.objects.all()] +@xmlrpc_func(returns='struct', args=['string']) +def dict_id(id=None): + """Get a Gbobject as a dict or as a list of dicts""" + if id: + return Gbobject.objects.get(id="{0}".format(id)) + else: + return [dict_id(id) for id in list_id()] |