Esempio n. 1
0
def reindex():
    from vars import mime_type_map
    from InformaCamUtils.elasticsearch import Elasticsearch

    elasticsearch = Elasticsearch()
    elasticsearch.createIndex(reindex=True)

    for mode in ["sources", "submissions"]:
        for root_, dirs_, files_ in os.walk(os.path.join(assets_root, mode)):
            for dir_ in dirs_:
                for root, dirs, files in os.walk(
                        os.path.join(assets_root, mode, dir_)):
                    data = {
                        '_id': dir_,
                        'asset_path': os.path.join(assets_root, mode, dir_)
                    }

                    for file in files:
                        if mode == "submissions":
                            if re.match(r'^(low_|med_|thumb_|high_)', file):
                                continue
                            else:
                                comps = file.split(".")
                                if len(comps) == 2 and re.match(
                                        r'(mkv|jpg)', comps[1]):
                                    data['file_name'] = file
                                    for mt, ext in mime_type_map.iteritems():
                                        if ext == comps[1]:
                                            data['mime_type'] = mt
                                            break
                                    break
                        elif mode == "sources":
                            if re.match(r'^(credentials|publicKey|baseImage_)',
                                        file):
                                continue
                            else:
                                data['file_name'] = file
                                break

                    print data

                    try:
                        if mode == "submissions":
                            submission = Submission(inflate=data, reindex=True)
                            print submission.emit()
                        elif mode == "sources":
                            source = Source(inflate=data, reindex=True)
                    except exceptions.ConnectionError as e:
                        print e
                        return
                    except AttributeError as e:
                        continue
Esempio n. 2
0
def reindex():
	from vars import mime_type_map
	from InformaCamUtils.elasticsearch import Elasticsearch
	
	elasticsearch = Elasticsearch()
	elasticsearch.createIndex(reindex=True)
	
	for mode in ["sources", "submissions"]:
		for root_, dirs_, files_ in os.walk(os.path.join(assets_root, mode)):
			for dir_ in dirs_:
				for root, dirs, files in os.walk(
					os.path.join(assets_root, mode, dir_)):
					data = {
						'_id' : dir_,
						'asset_path' : os.path.join(assets_root, mode, dir_)
					}
					
					for file in files:
						if mode == "submissions":
							if re.match(r'^(low_|med_|thumb_|high_)', file):
								continue
							else:
								comps = file.split(".")
								if len(comps) == 2 and re.match(r'(mkv|jpg)', comps[1]):
									data['file_name'] = file
									for mt, ext in mime_type_map.iteritems():
										if ext == comps[1]:
											data['mime_type'] = mt
											break
									break
						elif mode == "sources":
							if re.match(r'^(credentials|publicKey|baseImage_)', file):
								continue
							else:
								data['file_name'] = file
								break
					
					print data

					try:
						if mode == "submissions":
							submission = Submission(inflate=data, reindex=True)
							print submission.emit()
						elif mode == "sources":
							source = Source(inflate=data, reindex=True)
					except exceptions.ConnectionError as e:
						print e
						sys.exit()
					except AttributeError as e:
						continue
Esempio n. 3
0
def initElasticsearch():
	elasticsearch = Elasticsearch()
	elasticsearch.createIndex(reindex=True)