Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Converted many strings to unicode strings to reduce encoding errors.

  • Loading branch information...
commit 495f077dbe39c82c405cd243e1bbf7657fadb2f7 1 parent 2cd6bc3
@Vultaire authored
Showing with 30 additions and 25 deletions.
  1. +13 −13 r21buddy/oggpatch.py
  2. +17 −12 r21buddy/r21buddy.py
View
26 r21buddy/oggpatch.py
@@ -209,7 +209,7 @@ def get_packets(pages):
# I *think* the patch should still work - the patch
# operates on the page level, but this error is at the
# underlying packet; it shouldn't matter.
- logger.error("WARNING: Unterminated packet detected, ignoring.")
+ logger.error(u"WARNING: Unterminated packet detected, ignoring.")
self.pages = list(pages) # Needed to recreate stream with updated final page
@@ -249,8 +249,8 @@ def patch_length(self, new_length, verbose=True):
last_page = self.pages[-1]
if verbose:
- logger.info("Current granule position: {0}".format(last_page.granule_pos))
- logger.info("New granule position: {0}".format(new_granule_pos))
+ logger.info(u"Current granule position: {0}".format(last_page.granule_pos))
+ logger.info(u"New granule position: {0}".format(new_granule_pos))
# Replace last page with patched version
new_page_data = last_page.get_data_with_new_length(new_granule_pos)
@@ -460,15 +460,15 @@ def patch_file(input_file, target_length=TARGET_LENGTH,
output_file=None, verbose=True):
patched = False
if target_length < 0:
- logger.error("Bad length ({0}), not patching file".format(target_length))
+ logger.error(u"Bad length ({0}), not patching file".format(target_length))
return
with open(input_file, "rb") as infile:
bitstreams = list(get_bitstreams(infile))
for bitstream in bitstreams:
length = bitstream.get_length()
if verbose:
- logger.info("Current file length: {0}".format(pprint_time(length)))
- logger.info("Target file length: {0}".format(pprint_time(target_length)))
+ logger.info(u"Current file length: {0}".format(pprint_time(length)))
+ logger.info(u"Target file length: {0}".format(pprint_time(target_length)))
if length > target_length:
patched = True
bitstream.patch_length(target_length, verbose=verbose)
@@ -476,33 +476,33 @@ def patch_file(input_file, target_length=TARGET_LENGTH,
if output_file is None:
output_file = input_file
if verbose:
- logger.info("Writing patched file to {0}".format(output_file))
+ logger.info(u"Writing patched file to {0}".format(output_file))
with open(output_file, "wb") as outfile:
for bitstream in bitstreams:
bitstream.write_to_file(outfile)
elif verbose:
- logger.info("Not patching file; file already appears to be {0} or shorter.".format(
+ logger.info(u"Not patching file; file already appears to be {0} or shorter.".format(
pprint_time(target_length)))
def check_file(input_file, target_length, verbose=True):
if target_length < 0:
- logger.error("Bad length ({0}), not patching file".format(target_length))
+ logger.error(u"Bad length ({0}), not patching file".format(target_length))
return
with open(input_file, "rb") as infile:
bitstreams = list(get_bitstreams(infile))
for bitstream in bitstreams:
length = bitstream.get_length()
if verbose:
- logger.info("Current file length: {0}".format(pprint_time(length)))
- logger.info("Target file length: {0}".format(pprint_time(target_length)))
+ logger.info(u"Current file length: {0}".format(pprint_time(length)))
+ logger.info(u"Target file length: {0}".format(pprint_time(target_length)))
if length > target_length:
- logger.error("File exceeds {0}. Length: {1}".format(
+ logger.error(u"File exceeds {0}. Length: {1}".format(
pprint_time(target_length), pprint_time(length)))
return False
else:
if verbose:
- logger.info("File passes length check.")
+ logger.info(u"File passes length check.")
continue
return True
View
29 r21buddy/r21buddy.py
@@ -29,21 +29,26 @@ def parse_args():
return ap.parse_args()
def create_target_dir_structure(target_dir, verbose=False):
- song_dir = os.path.join(target_dir, "In The Groove 2", "Songs")
+ song_dir = os.path.join(target_dir, u"In The Groove 2", u"Songs")
if not os.path.exists(song_dir):
- os.makedirs(os.path.join(target_dir, "In The Groove 2", "Songs"))
+ os.makedirs(os.path.join(target_dir, u"In The Groove 2", u"Songs"))
if verbose:
- logger.info("Created directory: {0}".format(song_dir))
+ logger.info(u"Created directory: {0}".format(song_dir))
elif not os.path.isdir(song_dir):
raise Exception("Target path is not a directory", song_dir)
else:
if verbose:
- logger.info("Directory already exists: {0}".format(song_dir))
+ logger.info(u"Directory already exists: {0}".format(song_dir))
def copy_songs(input_path, target_dir, verbose=False):
+ logger.info(u"INPUT DIR: {0}".format(repr(input_path)))
all_files = [os.path.join(input_path, f) for f in os.listdir(input_path)]
dirs = [f for f in all_files if os.path.isdir(f)]
+ oddballs = [f for f in all_files if (not os.path.isdir(f)) and (not os.path.isfile(f))]
+ if len(oddballs) > 0:
+ logger.info(u"ODDBALLS: {0}".format(repr(oddballs)))
+
# If directories present: recurse into them.
if len(dirs) > 0:
for d in dirs:
@@ -66,22 +71,22 @@ def copy_songs(input_path, target_dir, verbose=False):
mp3_exists = any(f.endswith(".mp3") for f in all_files)
if not sm_exists:
- logger.error("Directory {0}: Could not find .sm; only .dwi was found. Skipping.".format(input_path))
+ logger.error(u"Directory {0}: Could not find .sm; only .dwi was found. Skipping.".format(input_path))
return
if not ogg_exists:
if any(f.endswith(".mp3") for f in all_files):
- logger.error("Directory {0}: Could not find .ogg; only .mp3 was found. Skipping.".format(input_path))
+ logger.error(u"Directory {0}: Could not find .ogg; only .mp3 was found. Skipping.".format(input_path))
else:
- logger.error("Directory {0}: Could not find .ogg. Skipping.".format(input_path))
+ logger.error(u"Directory {0}: Could not find .ogg. Skipping.".format(input_path))
return
# We are compatible. Check for destination directory; complain
# LOUDLY if not able to create it.
song_dir_name = os.path.split(input_path)[-1]
target_song_dir = os.path.join(
- target_dir, "In The Groove 2", "Songs", song_dir_name)
+ target_dir, u"In The Groove 2", u"Songs", song_dir_name)
if os.path.exists(target_song_dir):
- logger.error("ERROR: {0} already exists; not copying files from {1}.".format(target_song_dir, input_path))
+ logger.error(u"ERROR: {0} already exists; not copying files from {1}.".format(target_song_dir, input_path))
return
os.makedirs(target_song_dir)
@@ -90,11 +95,11 @@ def copy_songs(input_path, target_dir, verbose=False):
dest_file = os.path.join(
target_song_dir, os.path.basename(src_file))
if verbose:
- logger.info("Copying: {0}\n to: {1}".format(src_file, dest_file))
+ logger.info(u"Copying: {0}\n to: {1}".format(src_file, dest_file))
shutil.copyfile(src_file, dest_file)
def patch_length(target_dir, verbose=False):
- song_dir = os.path.join(target_dir, "In The Groove 2", "Songs")
+ song_dir = os.path.join(target_dir, u"In The Groove 2", u"Songs")
all_files = [os.path.join(song_dir, f) for f in os.listdir(song_dir)]
dirs = [d for d in all_files if os.path.isdir(d)]
for song_dir in dirs:
@@ -102,7 +107,7 @@ def patch_length(target_dir, verbose=False):
ogg_files = (f for f in song_files if f.endswith(".ogg"))
for ogg_file in ogg_files:
if verbose:
- logger.info("Patching file: {0}".format(ogg_file))
+ logger.info(u"Patching file: {0}".format(ogg_file))
oggpatch.patch_file(ogg_file, verbose=verbose)
def run(target_dir, input_paths, length_patch=True, verbose=False, ext_logger=None):
Please sign in to comment.
Something went wrong with that request. Please try again.