Exemplo n.º 1
0
def main():
    options = handle_options()

    #remove raw file if not exist on jpg (-j -r)
    if (options.raw and options.jpg):
        if not (os.path.isdir(options.raw) and os.path.isdir(options.jpg)):
            raise SystemExit("both raw and jpg needs to be directory")
        delete_files.delete_raw_from_jpg(options.jpg, options.raw)
        return

    #delete duplicate from source directory (-s -u)
    if (options.source and options.unique):
        delete_duplication(options.source)

    s = storage.Storage()

    #add files to exif storage (-s -e)
    if (options.source and options.exif):
        if not os.path.isdir(options.source):
            raise SystemExit("source must be directory")
        #deduplicate first
        delete_duplication(options.source)
        for f in os.listdir(options.source):
            fname = os.path.abspath(os.path.join(options.source, f))
            s.add_metadata(fname, json.dumps(exif.get(fname)))

    #move files from current location to destination location based on exif info
    if (options.source and options.destination):
        if not (os.path.isdir(options.source)
                and os.path.isdir(options.destination)):
            raise SystemExit("source and destination must both be directory")
        move_source_to_destination(options.source, options.destination)
Exemplo n.º 2
0
 def __init__(self, username, password, logger=None):
   """Initialize logger and Storage instance"""
   if not logger:
     logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s')
     self.logger = logging.getLogger(__name__)
   else:
     self.logger = logger
   self.db = storage.Storage(username, password)
Exemplo n.º 3
0
def move_source_to_destination(source, destination):
    """move source files to destination
    """
    s = storage.Storage()
    for f in os.listdir(source):
        fname = os.path.abspath(os.path.join(source, f))
        md5 = checksum.md5(fname)
        if s.has_key(fname, md5):
            print 'delete duplicate [%s]' % f
            delete_files.move_file(fname)
            continue
        tags = exif.get(fname)
        if not tags:
            continue
        s.add_metadata(fname, json.dumps(tags, ensure_ascii=False))
        relocate.move((fname, tags['DateTimeOriginal']), destination)
Exemplo n.º 4
0
def delete_duplication(source):
    """ delete duplicate from source directory
    """
    s = storage.Storage()
    if not os.path.isdir(source):
        raise SystemExit("source must be directory")
    for f in os.listdir(source):
        fname = os.path.abspath(os.path.join(source, f))
        md5 = checksum.md5(fname)
        if s.has_key(fname, md5):
            result = s.fetch_key(data=md5)[0][0]
            if result == fname:
                #same file
                continue
            else:
                print 'delete duplicate [%s] ::: original [%s]' % (f, result)
                delete_files.move_file(fname)
Exemplo n.º 5
0
 def testFormatDatetime(self):
     test_date = '2017-12-25T15:59:59.102938 msqedigrb msg'
     expected_time_str = '2017-12-25T15:59:59.102938'
     test_storage_object = storage.Storage()
     self.assertEqual(expected_time_str,
                      test_storage_object._FormatDatetime(test_date))
Exemplo n.º 6
0
 def setUp(self):
     self.db='.unittest.storage.engine.db'
     self.storage = storage.Storage(self.db)
Exemplo n.º 7
0
def store_stats(ip_addr, stats, username, password):
  #stats has the format: os, cpu_usage, mem_usage, uptime, event_logs
  db = storage.Storage(username, password)
  db_row_id = db.store_machine_stats(ip_addr, stats.split(','))
  global_logger.info('Stats recorded: %s', db_row_id)