コード例 #1
0
ファイル: backfill_checksum.py プロジェクト: jjdelc/Photolog
def migrate(conn):
    conn.execute('ALTER TABLE pictures ADD COLUMN checksum TEXT')

    total_ok, total_bad = 0, 0
    updates = []
    for picture in conn.execute('SELECT * FROM pictures'):
        local_path = join(BASE_PATH, picture['year'],
            '%s%s' % (picture['month'], picture['day']))
        name = picture['name']

        tries = [join(local_path, name), join(local_path, name.upper())]
        found, found_file, checksum = True, None, None
        for file in tries:
            try:
                checksum = file_checksum(file)
                found_file = file
                break
            except FileNotFoundError:
                pass
            found = False

        if found:
            total_ok += 1
            print("Checksum for: %s: %s" % (found_file, checksum))
            updates.append((picture['id'], checksum))
        else:
            print("File not found: %s" % local_path)
            total_bad += 1
    print('Total OK: %s - Bad: %s' % (total_ok, total_bad))

    for pic_id, checksum in updates:
        conn.execute('UPDATE pictures SET checksum =? WHERE id=?',
            [checksum, pic_id])
コード例 #2
0
ファイル: uploader.py プロジェクト: jjdelc/Photolog
def verify_exists(host, full_filepath, secret):
    verification = urljoin(host, '/photos/verify/')
    checksum = file_checksum(full_filepath)
    filename = os.path.basename(full_filepath)
    response = requests.get(verification, params={
        'filename': filename,
        'checksum': checksum
    }, headers={
        'X-PHOTOLOG-SECRET': secret
    })
    return response.status_code == 204
コード例 #3
0
ファイル: jobs.py プロジェクト: jjdelc/Photolog
 def _get_checksum(self):
     return base.file_checksum(self.full_filepath)