kopia lustrzana https://gitlab.com/zeograd/rnsutils
Improve pep8 compliance
rodzic
8a1719b35f
commit
8db917503b
4
pylintrc
4
pylintrc
|
@ -127,7 +127,7 @@ expected-line-ending-format=
|
|||
bad-functions=map,filter,input
|
||||
|
||||
# Good variable names which should always be accepted, separated by a comma
|
||||
good-names=i,j,k,ex,Run,_
|
||||
good-names=i,j,k,ex,e,Run,_
|
||||
|
||||
# Bad variable names which should always be refused, separated by a comma
|
||||
bad-names=foo,bar,baz,toto,tutu,tata
|
||||
|
@ -326,7 +326,7 @@ max-args=5
|
|||
ignored-argument-names=_.*
|
||||
|
||||
# Maximum number of locals for function / method body
|
||||
max-locals=15
|
||||
max-locals=18
|
||||
|
||||
# Maximum number of return / yield for function / method body
|
||||
max-returns=6
|
||||
|
|
|
@ -275,6 +275,6 @@ if __name__ == "__main__":
|
|||
instrument = RenoiseInstrument('basic.xrni')
|
||||
pprint.pprint(instrument)
|
||||
pprint.pprint(instrument.samples)
|
||||
# s = instrument.samples[0]
|
||||
# s = instrument.samples[0]
|
||||
# print(s.foo())
|
||||
instrument.save('generated.xrni')
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
"""lookup for mapping xml elements into custom python wrappers"""
|
||||
from lxml import etree
|
||||
from lxml.objectify import ObjectifyElementClassLookup
|
||||
|
||||
|
@ -5,10 +6,13 @@ from .instrument import RenoiseSample, RenoiseModulationSet
|
|||
|
||||
|
||||
class RenoiseClassLookup(etree.CustomElementClassLookup):
|
||||
"""mapping class for xml element to python class"""
|
||||
|
||||
def __init__(self):
|
||||
super(RenoiseClassLookup, self).__init__(fallback=ObjectifyElementClassLookup())
|
||||
|
||||
def lookup(self, node_type, document, namespace, name):
|
||||
"""mapping method for xml element to python class"""
|
||||
if name == 'Sample':
|
||||
return RenoiseSample
|
||||
elif name == 'ModulationSet':
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""project wide utilities, notably audio format guessing and encoding"""
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
|
@ -6,6 +8,9 @@ import tempfile
|
|||
|
||||
|
||||
def guesstimate_audio_extension(data):
|
||||
""":arg data audio file content
|
||||
:return file format extension guessed from file content"""
|
||||
|
||||
if len(data) > 8 and data[0:8] == b'fLaC\0\0\0\x22':
|
||||
return "flac"
|
||||
if len(data) > 3 and data[0:3] == b'Ogg':
|
||||
|
@ -19,7 +24,10 @@ ENCODING_OGG = "ogg"
|
|||
|
||||
|
||||
def _call_encoder(func):
|
||||
"""decorator for creating a temporary file, calling an encoder and cleaning temporary files"""
|
||||
|
||||
def inner(sample_content):
|
||||
"""actual wrapping function to create and clean temporary files around audio encoding"""
|
||||
out_format = guesstimate_audio_extension(sample_content)
|
||||
in_filename = tempfile.NamedTemporaryFile(suffix='.wav', delete=False).name
|
||||
out_filename = tempfile.NamedTemporaryFile(suffix='.{}'.format(out_format), delete=False).name
|
||||
|
@ -42,17 +50,20 @@ def _call_encoder(func):
|
|||
|
||||
@_call_encoder
|
||||
def _encode_flac(in_filename, out_filename):
|
||||
"""encode :arg in_filename into :arg out_filename using flac"""
|
||||
return subprocess.Popen(["flac", in_filename, "-f", "-o", out_filename], stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE)
|
||||
|
||||
|
||||
@_call_encoder
|
||||
def _encode_ogg(in_filename, out_filename):
|
||||
"""encode :arg in_filename into :arg out_filename using ogg vorbis"""
|
||||
return subprocess.Popen(["oggenc", in_filename, "-o", out_filename], stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE)
|
||||
|
||||
|
||||
def encode_audio_file(sample_content, encoding):
|
||||
"""encode :arg sample_content as audio file content into :arg encoding format"""
|
||||
if encoding == ENCODING_FLAC:
|
||||
return _encode_flac(sample_content)
|
||||
elif encoding == ENCODING_OGG:
|
||||
|
|
|
@ -64,7 +64,7 @@ def main(argv=None):
|
|||
# process options
|
||||
opts = parser.parse_args(argv)
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
indent = len(program_name) * " "
|
||||
sys.stderr.write(program_name + ": " + repr(e) + "\n")
|
||||
sys.stderr.write(indent + " for help use --help")
|
||||
|
@ -89,14 +89,14 @@ def main(argv=None):
|
|||
renoise_instrument.sample_data]
|
||||
|
||||
# save the output file
|
||||
filename_without_extension, extension = os.path.splitext(os.path.basename(xrni_filename))
|
||||
filename_without_extension, _ = os.path.splitext(os.path.basename(xrni_filename))
|
||||
output_filename = os.path.join(opts.output_dir or os.path.dirname(xrni_filename),
|
||||
'{}.{}.xrni'.format(filename_without_extension, opts.encoding))
|
||||
renoise_instrument.save(output_filename)
|
||||
|
||||
if not opts.quiet:
|
||||
print("Saved {}".format(output_filename))
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
if not opts.quiet:
|
||||
print("FAILED")
|
||||
logging.exception("Failed to reencode instrument")
|
||||
|
|
Ładowanie…
Reference in New Issue