def handle(self, *args, **options):
        if len(args) == 1:

            with zipfile.ZipFile(args[0], "r") as zip:
                meta = json.loads(zip.read('metadata.json'),
                                  object_hook=json_util.object_hook)
                fdict = json.loads(zip.read('fingerprint.json'),
                                   object_hook=json_util.object_hook)

                new_fingerprint = Fingerprint()
                new_hash = None

                level = self.__checkFeasibility(meta, fdict)

                if level == AS_IS:
                    self.stdout.write(
                        '-- Hash/fingerprint_id are free, import as is on exported file.\n'
                    )

                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__import(zip, args[0], new_fingerprint)

                elif level == NEW_IDS:
                    self.stdout.write(
                        '-- Hash/fingerprint_id are occupied, importing with a new id.\n'
                    )
                    new_hash = generate_hash()

                    fdict['fingerprint_hash'] = new_hash
                    del fdict['id']
                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__addShares(meta, new_fingerprint)

                    self.__import(zip,
                                  args[0],
                                  new_fingerprint,
                                  replacing=True)

                else:  # impossible
                    self.stdout.write(
                        '-- ERROR: Impossible to import fingerprint, the questionnaire doesnt exist, or doesnt match the slug.'
                    )

        else:
            self.stdout.write(
                '-- USAGE: \n    ' +
                'python manage.py fingerprint_import <path_file>' + '\n\n')
    def handle(self, *args, **options):
        if len(args) == 1:

            with zipfile.ZipFile(args[0],"r") as zip:
                meta = json.loads(zip.read('metadata.json'),object_hook=json_util.object_hook)
                fdict = json.loads(zip.read('fingerprint.json'),object_hook=json_util.object_hook)

                new_fingerprint = Fingerprint()
                new_hash =None

                level = self.__checkFeasibility(meta, fdict)

                if level == AS_IS:
                    self.stdout.write('-- Hash/fingerprint_id are free, import as is on exported file.\n')

                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__import(zip, args[0], new_fingerprint)

                elif level == NEW_IDS:
                    self.stdout.write('-- Hash/fingerprint_id are occupied, importing with a new id.\n')
                    new_hash = generate_hash()

                    fdict['fingerprint_hash'] = new_hash
                    del fdict['id']
                    new_fingerprint.__dict__.update(fdict)

                    new_fingerprint.save()

                    self.__addShares(meta, new_fingerprint)

                    self.__import(zip, args[0], new_fingerprint, replacing=True)

                else: # impossible
                    self.stdout.write('-- ERROR: Impossible to import fingerprint, the questionnaire doesnt exist, or doesnt match the slug.')


        else:
            self.stdout.write('-- USAGE: \n    '+
                'python manage.py fingerprint_import <path_file>'+
                '\n\n')
Beispiel #3
0
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from fingerprint.models import Fingerprint
from searchengine.search_indexes import CoreEngine
import sys

print '\nbegin import of fingerprint hashes to database...\n'

c = CoreEngine()
results = c.search_fingerprint('*:*')
for result in results:
	fingerprint_id = result['id']
	print fingerprint_id
	if not fingerprint_id.startswith("questionaire_"):
		try:
			fp = Fingerprint(fingerprint_hash=fingerprint_id)
			fp.save()
		except:
			print fingerprint_id + ' already in DB'

print '\nend!'