# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass
# 
# def printStatus(trace, message):
#     printMessage('INFO', trace, message)


import os, sys, array
import numpy as np
from basic.common import ROOT_PATH, checkToSkip, makedirsforfile, printStatus
from basic.util import readImageSet
    from optparse import OptionParser
                    vec = np.array(vec, dtype=np.float32)
                    vec.tofile(fw)
                    newimset.append(im)
            del res[:]
            if i%1e5 == 0:
                printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))
        fr.close()       
        printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))
                        
    fw.close()
    printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))
    
    idfile = os.path.join(os.path.split(resfile)[0], 'id.txt')
    with open(idfile, 'w') as fw:
        fw.write(' '.join(newimset))
        fw.close()
        
    shapefile = os.path.join(os.path.split(resfile)[0], 'shape.txt')
    with open(shapefile, 'w') as fw:
        fw.write('%d %d' % (len(newimset), feat_dim))
        fw.close()



def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = OptionParser(usage="""usage: %prog [options] feature srcCollections  newCollection""")
    parser.add_option("--overwrite", default=0, type="int", help="overwrite existing file (default=0)")

# Path: basic/common.py
# ROOT_PATH = "/home/b/VisualSearch1"
# 
# def checkToSkip(filename, overwrite):
#     if os.path.exists(filename):
#         print ("%s exists." % filename),
#         if overwrite:
#             print ("overwrite")
#             return 0
#         else:
#             print ("skip")
#             return 1
#     return 0    
# 
# def makedirsforfile(filename):
#     try:
#         os.makedirs(os.path.split(filename)[0])
#     except:
#         pass
# 
# def printStatus(trace, message):
#     printMessage('INFO', trace, message)


# Path: simpleknn/merge_feat.py
import os, sys, array
import numpy as np
from basic.common import ROOT_PATH, checkToSkip, makedirsforfile, printStatus
from basic.util import readImageSet
    from optparse import OptionParser

                    vec = np.array(vec, dtype=np.float32)
                    vec.tofile(fw)
                    newimset.append(im)
            del res[:]
            if i%1e5 == 0:
                printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))
        fr.close()       
        printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))
                        
    fw.close()
    printStatus(INFO, '%d parsed, %d obtained' % (len(seen), len(newimset)))
    
    idfile = os.path.join(os.path.split(resfile)[0], 'id.txt')
    with open(idfile, 'w') as fw:
        fw.write(' '.join(newimset))
        fw.close()
        
    shapefile = os.path.join(os.path.split(resfile)[0], 'shape.txt')
    with open(shapefile, 'w') as fw:
        fw.write('%d %d' % (len(newimset), feat_dim))
        fw.close()



def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = OptionParser(usage="""usage: %prog [options] feature srcCollections  newCollection""")
    parser.add_option("--overwrite", default=0, type="int", help="overwrite existing file (default=0)")

    parser.add_option("--rootpath", default=ROOT_PATH, type="string", help="rootpath where data are stored (default: %s)" % ROOT_PATH)