Skip to content

Commit

Permalink
Autoformatting source
Browse files Browse the repository at this point in the history
Most of the groundwork to make linter happy:
- tabs -> 4 spaces
- 2 lines separation on module-level statements
- non-compliant indentation
- etc
  • Loading branch information
ImanolBarba committed Jul 9, 2023
1 parent 3adf9aa commit ca8c50e
Show file tree
Hide file tree
Showing 9 changed files with 5,315 additions and 5,225 deletions.
1,767 changes: 887 additions & 880 deletions gui.py

Large diffs are not rendered by default.

366 changes: 183 additions & 183 deletions guires.py

Large diffs are not rendered by default.

1,438 changes: 727 additions & 711 deletions lzari.py

Large diffs are not rendered by default.

1,475 changes: 751 additions & 724 deletions mymc.py

Large diffs are not rendered by default.

3,869 changes: 1,941 additions & 1,928 deletions ps2mc.py

Large diffs are not rendered by default.

201 changes: 104 additions & 97 deletions ps2mc_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,42 @@

"""Functions for working with PS2 memory card directory entries."""

import os
import calendar
import time
import struct
_SCCS_ID = "@(#) mymc ps2mc_dir.py 1.5 23/07/06 06:30:13\n"

import struct
import time
import calendar
import os

PS2MC_DIRENT_LENGTH = 512

DF_READ = 0x0001
DF_WRITE = 0x0002
DF_EXECUTE = 0x0004
DF_RWX = DF_READ | DF_WRITE | DF_EXECUTE
DF_PROTECTED = 0x0008
DF_FILE = 0x0010
DF_DIR = 0x0020
DF_O_DCREAT = 0x0040
DF_0080 = 0x0080
DF_0100 = 0x0100
DF_O_CREAT = 0x0200
DF_0400 = 0x0400
DF_POCKETSTN = 0x0800
DF_PSX = 0x1000
DF_HIDDEN = 0x2000
DF_4000 = 0x4000
DF_EXISTS = 0x8000
DF_READ = 0x0001
DF_WRITE = 0x0002
DF_EXECUTE = 0x0004
DF_RWX = DF_READ | DF_WRITE | DF_EXECUTE
DF_PROTECTED = 0x0008
DF_FILE = 0x0010
DF_DIR = 0x0020
DF_O_DCREAT = 0x0040
DF_0080 = 0x0080
DF_0100 = 0x0100
DF_O_CREAT = 0x0200
DF_0400 = 0x0400
DF_POCKETSTN = 0x0800
DF_PSX = 0x1000
DF_HIDDEN = 0x2000
DF_4000 = 0x4000
DF_EXISTS = 0x8000


def zero_terminate(s):
"""Truncate a string at the first NUL ('\0') character, if any."""

i = s.find(b'\0')
if i == -1:
return s
return s[:i]
"""Truncate a string at the first NUL ('\0') character, if any."""

i = s.find(b'\0')
if i == -1:
return s
return s[:i]


# mode, ???, length, created,
# fat_cluster, parent_entry, modified, attr,
Expand All @@ -52,86 +54,91 @@ def zero_terminate(s):

#
# Use the new Struct object if available
#
#
if hasattr(struct, "Struct"):
_dirent_struct = struct.Struct(_dirent_fmt)
_tod_struct = struct.Struct(_tod_fmt)

def unpack_tod(s):
return _tod_struct.unpack(s)
def pack_tod(tod):
return _tod_struct.pack(tod)
def unpack_dirent(s):
ent = _dirent_struct.unpack(s)
ent = list(ent)
ent[3] = _tod_struct.unpack(ent[3])
ent[6] = _tod_struct.unpack(ent[6])
ent[8] = zero_terminate(ent[8]).decode("ascii")
return ent

def pack_dirent(ent):
ent = list(ent)
ent[3] = _tod_struct.pack(*ent[3])
ent[6] = _tod_struct.pack(*ent[6])
ent[8] = ent[8].encode("ascii")
return _dirent_struct.pack(*ent)
_dirent_struct = struct.Struct(_dirent_fmt)
_tod_struct = struct.Struct(_tod_fmt)

def unpack_tod(s):
return _tod_struct.unpack(s)

def pack_tod(tod):
return _tod_struct.pack(tod)

def unpack_dirent(s):
ent = _dirent_struct.unpack(s)
ent = list(ent)
ent[3] = _tod_struct.unpack(ent[3])
ent[6] = _tod_struct.unpack(ent[6])
ent[8] = zero_terminate(ent[8]).decode("ascii")
return ent

def pack_dirent(ent):
ent = list(ent)
ent[3] = _tod_struct.pack(*ent[3])
ent[6] = _tod_struct.pack(*ent[6])
ent[8] = ent[8].encode("ascii")
return _dirent_struct.pack(*ent)
else:
def unpack_tod(s):
return struct.unpack(_tod_fmt, s)

def pack_tod(tod):
return struct.pack(_tod_fmt, tod)

def unpack_dirent(s):
# mode, ???, length, created,
# fat_cluster, parent_entry, modified, attr,
# name
ent = struct.unpack(_dirent_fmt, s)
ent = list(ent)
ent[3] = struct.unpack(_tod_fmt, ent[3])
ent[6] = struct.unpack(_tod_fmt, ent[6])
ent[8] = zero_terminate(ent[8])
return ent

def pack_dirent(ent):
ent = list(ent)
ent[3] = struct.pack(_tod_fmt, *ent[3])
ent[6] = struct.pack(_tod_fmt, *ent[6])
ent[8] = ent[8].encode("ascii")
return struct.pack(_dirent_fmt, *ent)
def unpack_tod(s):
return struct.unpack(_tod_fmt, s)

def pack_tod(tod):
return struct.pack(_tod_fmt, tod)

def unpack_dirent(s):
# mode, ???, length, created,
# fat_cluster, parent_entry, modified, attr,
# name
ent = struct.unpack(_dirent_fmt, s)
ent = list(ent)
ent[3] = struct.unpack(_tod_fmt, ent[3])
ent[6] = struct.unpack(_tod_fmt, ent[6])
ent[8] = zero_terminate(ent[8])
return ent

def pack_dirent(ent):
ent = list(ent)
ent[3] = struct.pack(_tod_fmt, *ent[3])
ent[6] = struct.pack(_tod_fmt, *ent[6])
ent[8] = ent[8].encode("ascii")
return struct.pack(_dirent_fmt, *ent)


def time_to_tod(when):
"""Convert a Python time value to a ToD tuple"""

tm = time.gmtime(when + 9 * 3600)
return (tm.tm_sec, tm.tm_min, tm.tm_hour,
tm.tm_mday, tm.tm_mon, tm.tm_year)
"""Convert a Python time value to a ToD tuple"""

tm = time.gmtime(when + 9 * 3600)
return (tm.tm_sec, tm.tm_min, tm.tm_hour,
tm.tm_mday, tm.tm_mon, tm.tm_year)


def tod_to_time(tod):
"""Convert a ToD tuple to a Python time value."""

try:
month = tod[4]
if month == 0:
month = 1
return calendar.timegm((tod[5], month, tod[3],
tod[2], tod[1], tod[0],
None, None, 0)) - 9 * 3600
except ValueError:
return 0

"""Convert a ToD tuple to a Python time value."""

try:
month = tod[4]
if month == 0:
month = 1
return calendar.timegm((tod[5], month, tod[3],
tod[2], tod[1], tod[0],
None, None, 0)) - 9 * 3600
except ValueError:
return 0


def tod_now():
"""Get the current time as a ToD tuple."""
return time_to_tod(time.time())
"""Get the current time as a ToD tuple."""
return time_to_tod(time.time())


def tod_from_file(filename):
return time_to_tod(os.stat(filename).st_mtime)
return time_to_tod(os.stat(filename).st_mtime)


def mode_is_file(mode):
return (mode & (DF_FILE | DF_DIR | DF_EXISTS)) == (DF_FILE | DF_EXISTS)
return (mode & (DF_FILE | DF_DIR | DF_EXISTS)) == (DF_FILE | DF_EXISTS)

def mode_is_dir(mode):
return (mode & (DF_FILE | DF_DIR | DF_EXISTS)) == (DF_DIR | DF_EXISTS)

def mode_is_dir(mode):
return (mode & (DF_FILE | DF_DIR | DF_EXISTS)) == (DF_DIR | DF_EXISTS)
Loading

0 comments on commit ca8c50e

Please sign in to comment.