diff options
author | gnowgi <nagarjun@gnowledge.org> | 2012-08-20 14:59:04 +0530 |
---|---|---|
committer | gnowgi <nagarjun@gnowledge.org> | 2012-08-20 14:59:04 +0530 |
commit | 02b3d1e20002f4388734e62b6d1afbff5b383ba3 (patch) | |
tree | 0f1c248199d700091cfeaaca33d8d2df90ce23ab /gstudio/management | |
parent | fd9cc8dfc4a21b606eddf9184da10aebe00f2644 (diff) | |
parent | 1172262373b8b18b6266f49d62e8dc917e007ee5 (diff) | |
download | gnowsys-02b3d1e20002f4388734e62b6d1afbff5b383ba3.tar.gz |
Merge branch 'master' of git.sv.gnu.org:/srv/git/gnowsys
Diffstat (limited to 'gstudio/management')
-rw-r--r-- | gstudio/management/commands/sync-gbobjects.py | 112 | ||||
-rw-r--r-- | gstudio/management/commands/sync-instances.py | 35 |
2 files changed, 79 insertions, 68 deletions
diff --git a/gstudio/management/commands/sync-gbobjects.py b/gstudio/management/commands/sync-gbobjects.py index faf4274..2e8c955 100644 --- a/gstudio/management/commands/sync-gbobjects.py +++ b/gstudio/management/commands/sync-gbobjects.py @@ -13,59 +13,59 @@ # 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() +# 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/management/commands/sync-instances.py b/gstudio/management/commands/sync-instances.py index 632e9ef..20607bb 100644 --- a/gstudio/management/commands/sync-instances.py +++ b/gstudio/management/commands/sync-instances.py @@ -20,10 +20,6 @@ import re import sys from datetime import datetime -from objectapp.models import Gbobject -from objectapp.models import Objecttype -from objectapp.models import Attributetype -from objectapp.models import Relationtype from objectapp.models import ObjectDoesNotExist # from gstudio.xmlrpc.metaweblog import class_checker @@ -40,7 +36,9 @@ class Command(BaseCommand): """Gets all Gbobjects from a specified server""" option_list = BaseCommand.option_list + ( make_option("--server", action="store", type="string", - dest="server", help="Specify an ip"),) + dest="server", help="Specify IP address or URI"), + make_option("--instance", action="store", type="string", + dest="instance", help="Specify an instance"),) def handle(self, *args, **options): def class_checker(m): @@ -83,8 +81,9 @@ class Command(BaseCommand): def str_to_int(string): return [int(x) for x in string] + # Weird check for DateTime objects + for key in i.keys(): - # Weird check for DateTime objects if "make_comparable" in dir(i[key]): dt = DateTime().make_comparable(i[key])[1] dt = str_to_int(group(re.search(pattern, dt))) @@ -94,19 +93,31 @@ class Command(BaseCommand): class_checker(module)[instance](**i).save() except (ObjectDoesNotExist, IntegrityError): - sys.stderr.write("Object matching query does not exist\n") + sys.stderr.write("sync-instances.py:55: " + "Object matching query does not exist\n") except ValueError: - sys.stderr.write("Object already exists\n") + sys.stderr.write("sync-instances.py:93: " + "Object already exists\n") server = options["server"] srv = ServerProxy(server, allow_none=True) + instance = options["instance"] + objcc = class_checker(objmodels) gstcc = class_checker(gstmodels) - for i in objcc.keys(): - parse("objectapp.models", i) + if instance: + if instance in objkeys: + parse("objectapp.models", instance) + + if instance in gstkeys: + parse("gstudio.models", instance) + + else: + for i in objkeys: + parse("objectapp.models", i) - for i in gstcc.keys(): - parse("gstudio.models", i) + for i in gstkeys: + parse("gstudio.models", i) |