automated reformat pass

This commit is contained in:
lynxize 2025-06-20 08:58:24 -06:00
parent 66fe9bc514
commit d0d8588e5f
Signed by: lynxize
GPG key ID: 8615849B8532CD77

View file

@ -14,15 +14,18 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from __future__ import print_function
from __future__ import division from __future__ import division
from past.builtins import cmp from __future__ import print_function
from builtins import chr from builtins import chr
from builtins import input from builtins import input
from builtins import map from builtins import map
from builtins import range from builtins import range
from past.utils import old_div
from functools import reduce from functools import reduce
from past.builtins import cmp
from past.utils import old_div
__title__ = "KeyJ's iPod shuffle Database Builder" __title__ = "KeyJ's iPod shuffle Database Builder"
__version__ = "1.0" __version__ = "1.0"
__author__ = "Martin Fiedler" __author__ = "Martin Fiedler"
@ -71,9 +74,9 @@ __email__="martin.fiedler@gmx.net"
* initial public release, Win32 only * initial public release, Win32 only
""" """
import sys, os, os.path, array, getopt, random, fnmatch, operator, string
import sys,os,os.path,array,getopt,random,types,fnmatch,operator,string # @formatter:off
KnownProps = ('filename', 'size', 'ignore', 'type', 'shuffle', 'reuse', 'bookmark') KnownProps = ('filename', 'size', 'ignore', 'type', 'shuffle', 'reuse', 'bookmark')
Rules = [ Rules = [
([('filename', '~', '*.mp3')], {'type': 1, 'shuffle': 1, 'bookmark': 0}), ([('filename', '~', '*.mp3')], {'type': 1, 'shuffle': 1, 'bookmark': 0}),
@ -85,6 +88,7 @@ Rules=[
([('filename', '~', '*.announce.???')], { 'shuffle': 0, 'bookmark': 0}), ([('filename', '~', '*.announce.???')], { 'shuffle': 0, 'bookmark': 0}),
([('filename', '~', '/recycled/*')], {'ignore': 1}), ([('filename', '~', '/recycled/*')], {'ignore': 1}),
] ]
# @formatter:on
Options = { Options = {
"volume": None, "volume": None,
@ -179,6 +183,7 @@ def ParseValue(val):
except ValueError: except ValueError:
return val return val
def ParseRule(rule): def ParseRule(rule):
sep_pos = min([rule.find(sep) for sep in "~=<>" if rule.find(sep) > 0]) sep_pos = min([rule.find(sep) for sep in "~=<>" if rule.find(sep) > 0])
prop = rule[:sep_pos].strip() prop = rule[:sep_pos].strip()
@ -186,12 +191,14 @@ def ParseRule(rule):
log("WARNING: unknown property `%s'" % prop) log("WARNING: unknown property `%s'" % prop)
return (prop, rule[sep_pos], ParseValue(rule[sep_pos + 1:].strip())) return (prop, rule[sep_pos], ParseValue(rule[sep_pos + 1:].strip()))
def ParseAction(action): def ParseAction(action):
prop, value = list(map(string.strip, action.split('=', 1))) prop, value = list(map(string.strip, action.split('=', 1)))
if not prop in KnownProps: if not prop in KnownProps:
log("WARNING: unknown property `%s'" % prop) log("WARNING: unknown property `%s'" % prop)
return (prop, ParseValue(value)) return (prop, ParseValue(value))
def ParseRuleLine(line): def ParseRuleLine(line):
line = line.strip() line = line.strip()
if not (line) or line[0] == "#": if not (line) or line[0] == "#":
@ -219,6 +226,7 @@ def safe_char(c):
return c return c
return "_" return "_"
def rename_safely(path, name): def rename_safely(path, name):
base, ext = os.path.splitext(name) base, ext = os.path.splitext(name)
newname = ''.join(map(safe_char, base)) newname = ''.join(map(safe_char, base))
@ -283,12 +291,14 @@ def make_key(s):
if s[j].isdigit(): j += 1 if s[j].isdigit(): j += 1
return (s[:i], int(s[i:j]), make_key(s[j:])) return (s[:i], int(s[i:j]), make_key(s[j:]))
def key_repr(x): def key_repr(x):
if type(x) == tuple: if type(x) == tuple:
return "%s%d%s" % (x[0], x[1], key_repr(x[2])) return "%s%d%s" % (x[0], x[1], key_repr(x[2]))
else: else:
return x return x
def cmp_key(a, b): def cmp_key(a, b):
if type(a) == tuple and type(b) == tuple: if type(a) == tuple and type(b) == tuple:
return cmp(a[0], b[0]) or cmp(a[1], b[1]) or cmp_key(a[2], b[2]) return cmp(a[0], b[0]) or cmp(a[1], b[1]) or cmp_key(a[2], b[2])
@ -347,7 +357,8 @@ def browse(path, interactive):
for dir in subdirs: for dir in subdirs:
subpath = "%s/%s" % (path, dir) subpath = "%s/%s" % (path, dir)
try: try:
files.extend([x for x in [file_entry(subpath,name,dir+"/") for name in os.listdir(subpath)] if x and x[0]]) files.extend(
[x for x in [file_entry(subpath, name, dir + "/") for name in os.listdir(subpath)] if x and x[0]])
except OSError: except OSError:
pass pass
@ -376,6 +387,7 @@ def stringval(i):
if i < 0: i += 0x1000000 if i < 0: i += 0x1000000
return "%c%c%c" % (i & 0xFF, (i >> 8) & 0xFF, (i >> 16) & 0xFF) return "%c%c%c" % (i & 0xFF, (i >> 8) & 0xFF, (i >> 16) & 0xFF)
def listval(i): def listval(i):
if i < 0: i += 0x1000000 if i < 0: i += 0x1000000
return [i & 0xFF, (i >> 8) & 0xFF, (i >> 16) & 0xFF] return [i & 0xFF, (i >> 8) & 0xFF, (i >> 16) & 0xFF]
@ -438,7 +450,9 @@ def smart_shuffle():
if not domains[d]: continue if not domains[d]: continue
for n in domains[d]: for n in domains[d]:
# find slices where the nearest track of the same domain is far away # find slices where the nearest track of the same domain is far away
metric=[min([slice_count]+[min(abs(s-u),abs(s-u+slice_count),abs(s-u-slice_count)) for u in used]) for s in range(slice_count)] metric = [
min([slice_count] + [min(abs(s - u), abs(s - u + slice_count), abs(s - u - slice_count)) for u in used])
for s in range(slice_count)]
thresh = old_div((max(metric) + 1), 2) thresh = old_div((max(metric) + 1), 2)
farthest = [s for s in range(slice_count) if metric[s] >= thresh] farthest = [s for s in range(slice_count) if metric[s] >= thresh]
@ -603,10 +617,12 @@ def opterr(msg):
print("use `%s -h' to get help" % sys.argv[0]) print("use `%s -h' to get help" % sys.argv[0])
sys.exit(1) sys.exit(1)
def parse_options(): def parse_options():
try: try:
opts, args = getopt.getopt(sys.argv[1:], "hiv:snlfL:r", \ opts, args = getopt.getopt(sys.argv[1:], "hiv:snlfL:r", \
["help","interactive","volume=","nosmart","nochdir","nolog","force","logfile=","rename"]) ["help", "interactive", "volume=", "nosmart", "nochdir", "nolog", "force",
"logfile=", "rename"])
except getopt.GetoptError as message: except getopt.GetoptError as message:
opterr(message) opterr(message)
for opt, arg in opts: for opt, arg in opts: