def handle(self, *args, **kwargs): if args.__len__() < 2: raise CommandError(_(u"path(xform instances) username")) path = args[0] username = args[1] try: user = User.objects.get(username=username) except User.DoesNotExist: raise CommandError(_(u"Invalid username %s") % username) debug = False if debug: self.stdout.write(_(u"[Importing XForm Instances from %(path)s]\n") % {'path': path}) im_count = len(glob.glob(os.path.join(IMAGES_DIR, '*'))) self.stdout.write(_(u"Before Parse:")) self.stdout.write(_(u" --> Images: %(nb)d") % {'nb': im_count}) self.stdout.write((_(u" --> Instances: %(nb)d") % {'nb': Instance.objects.count()})) import_instances_from_zip(path, user) if debug: im_count2 = len(glob.glob(os.path.join(IMAGES_DIR, '*'))) self.stdout.write(_(u"After Parse:")) self.stdout.write(_(u" --> Images: %(nb)d") % {'nb': im_count2}) self.stdout.write((_(u" --> Instances: %(nb)d") % {'nb': Instance.objects.count()}))
def handle(self, *args, **kwargs): if len(args) < 2: raise CommandError(_("Usage: <command> username file/path.")) username = args[0] path = args[1] try: user = User.objects.get(username=username) except User.DoesNotExist: raise CommandError( _("The specified user '%s' does not exist.") % username) # make sure path exists if not os.path.exists(path): raise CommandError( _("The specified path '%s' does not exist.") % path) for dir, subdirs, files in os.walk(path): # check if the dir has an odk directory if "odk" in subdirs: # dont walk further down this dir subdirs.remove("odk") self.stdout.write(_("Importing from dir %s..\n") % dir) results = import_instances_from_path(dir, user) self.log_import(results) for file in files: filepath = os.path.join(path, file) if os.path.isfile(filepath) and\ os.path.splitext(filepath)[1].lower() == ".zip": self.stdout.write( _("Importing from zip at %s..\n") % filepath) results = import_instances_from_zip(filepath, user) self.log_import(results)
def handle(self, *args, **kwargs): if len(args) < 2: raise CommandError(_("Usage: <command> username file/path.")) username = args[0] path = args[1] try: user = User.objects.get(username=username) except User.DoesNotExist: raise CommandError(_( "The specified user '%s' does not exist.") % username) # make sure path exists if not os.path.exists(path): raise CommandError(_( "The specified path '%s' does not exist.") % path) for dir, subdirs, files in os.walk(path): # check if the dir has an odk directory if "odk" in subdirs: # dont walk further down this dir subdirs.remove("odk") self.stdout.write(_("Importing from dir %s..\n") % dir) results = import_instances_from_path(dir, user) self.log_import(results) for file in files: filepath = os.path.join(path, file) if os.path.isfile(filepath) and\ os.path.splitext(filepath)[1].lower() == ".zip": self.stdout.write(_( "Importing from zip at %s..\n") % filepath) results = import_instances_from_zip(filepath, user) self.log_import(results)