Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Automatically create the profile file
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
mineo committed May 20, 2016
1 parent 46139ea commit 759c787
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion abzer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


from .abzer import Abzer
from .util import collect_files, make_argparser, read_config
from .util import collect_files, create_profile_file, make_argparser, read_config
from os.path import isfile
from sys import exit

Expand Down Expand Up @@ -38,6 +38,9 @@ def main():

safety_check(config)

create_profile_file(config.get("essentia", "path"),
config.get("essentia", "profile"))

files = []

for name in args.filenames:
Expand Down
7 changes: 7 additions & 0 deletions abzer/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
"profile": join(DEFAULT_PATH, "profile.yaml")}
HEADERS = {"User-Agent": "abzer %s (https://github.com/mineo/abzer)" % version}
URL_BASE = "http://acousticbrainz.org/%s/low-level"

PROFILE_TEMPLATE = """requireMbid: true
indent: 0
mergeValues:
metadata:
version:
essentia_build_sha: {sha}"""
16 changes: 16 additions & 0 deletions abzer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@
import logging

from . import const
from hashlib import sha1
from os import cpu_count, walk
from os.path import join


def create_profile_file(essentia_path, profile_path):
"""
:param str essentia_path:
:param str profile_path:
"""
hash_ = sha1()
with open(essentia_path, "rb") as fp:
hash_.update(fp.read())
digest = hash_.hexdigest()
profile = const.PROFILE_TEMPLATE.format(sha=digest)
logging.debug("Writing a profile with SHA1 %s to %s", digest, profile_path)
with open(profile_path, "w") as fp:
fp.write(profile)


def collect_files(dir):
for dirpath, dirnames, filenames in walk(dir):
for filename in filenames:
Expand Down

0 comments on commit 759c787

Please sign in to comment.