Commit Graph

42 Commits

Author SHA1 Message Date
T. Joseph Carter 48f65d6f55 Lint cppo: Docstrings, warning disables
This actually disables all pylint warnings we haven't fixed because, as of now,
we don't intend to fix them.  The arg parsing is suboptimal, but if you can make
sure that existing scripts using cppo don't break by turning this into argparse
code, be my guest.  I didn't see an obvious way to do it any better than what we
have now.  When cppo is rewritten, we'll create a new runner with its own
argparse-based command parser.  Until then, I'm inclined to leave it be.

This is just part of a larger rewrite I started working on, but ... it's not
needed now.
2017-07-19 08:47:17 -07:00
T. Joseph Carter 0d17a525ac Add comments to cppo arguments
Duplicating the information from the usage here made it clear that a couple of
our arguments are undocumented.  Breaking up a larger effort into smaller pieces
so that the changes are more visible here.
2017-07-19 08:27:37 -07:00
T. Joseph Carter b55abc4baf Rename main cppo function to ... main :) 2017-07-19 08:19:00 -07:00
T. Joseph Carter 894225d1fa Use LOG, move logging setup to cppo
The actual logging configuration belongs in the application, not a module.  In a
module, it's always going to do what the module says to do.  And that's fine for
cppo which is a script that works the way it does, but we have bigger plans for
this code.  It's now in the cppo module.

We've stopped using log from blocksfree.logging, favoring LOG instead, so we
have removed it.
2017-07-18 18:19:57 -07:00
T. Joseph Carter 5915060db0 A little more style consistency
Basically cleaning out my stash stack--the stash this came from had been mostly
applied elsewhere already, leaving only a few stray ()s.  Figured it was a good
time to PEP 8 the end-of-line comments just so there was something here to
actually commit.
2017-07-08 04:01:57 -07:00
T. Joseph Carter 330c90d830 Fix ugly double import from blocksfree.legacy 2017-07-07 09:02:02 -07:00
T. Joseph Carter b543ea2f2d Finish removing arg parsing from legacy
You now simply stuff g with the appropriate options and run the thing.  You
could even modify the function to take those things as arguments now, but I
didn't do that for now.
2017-07-07 08:57:09 -07:00
T. Joseph Carter e266f0070c Correct docstring re: Python minimum
At present we actually have a reasonably high Python minimum of 3.5.  We could
back that off to 3.3 without much effort or perhaps even 3.2.  Once we're a
little closer to something to release, we should consider doing that.
2017-07-07 08:34:38 -07:00
T. Joseph Carter ae3a12507b Fix arg parsing, move arg processing to cppo
Not quite finished with this, but the goal here is not have args being passed
in to the legacy cppo at all.  The g namespace is not ideal, but it does work
and it isolates the legacy code from needing to understand what's going on in
the shell level.  So we'll take advantage of that for the time being.

The bigger problem was that when I moved the arg parsing out of cppo, I failed
to move all of it--a block that checked the number of args got lost.  Restored.
2017-07-07 08:34:38 -07:00
T. Joseph Carter 5d97a75efb Move argument parsing out of legacy.py
The point is to separate the CLI interface to cppo from the inner logic so that
we can begin replacing the legacy code with proper implementations thereof.
This isn't 100% complete in that regard--we still need to pass args to the
legacy main function--but the part of cppo that will survive this whole process
is now functionally isolated from the part that's likely to get replaced to a
large degree.
2017-07-07 07:33:26 -07:00
T. Joseph Carter 5bc600eaf7 Move cppo to blocksfree package 2017-07-07 07:01:27 -07:00
T. Joseph Carter 3f90743d56 Add license, Copyright notices, history doc
The history document is kind of a mishmash of explanation about what decisions
have lead to what this project is trying to do and why this rather than other
things, such as improving AppleCommander.  (Ohh, it has the reason for that
believe me--die in the cash-consuming fire of the Internet's rage, Oracle!)

More importantly, there are Copyright notices and the GNU GPL v2.
2017-07-07 06:29:19 -07:00
T. Joseph Carter 82d851e39a Create blocksfree package for logger
The section of cppo containing the logging code has been moved to its own very
short module inside a (bare) Python package.  This is messily done for now, but
I wanted this to be a minimal commit.
2017-07-07 02:21:42 -07:00
T. Joseph Carter 60b9d1f3c6 Test 2mg comment/creator blocks are "valid"
CiderPress checks that these optional areas are actually as long as the header
says they are and discards them if they're not.  This seems like a useful
heuristic.  It happens to be the only one we can perform.  :)
2017-07-03 05:21:41 -07:00
T. Joseph Carter 48ee2057c5 Alternate 2mg implementation
Rwrite of the 2mg parsing code which saves the comment and creator blocks in
memory by putting the code into the Disk class.

Doesn't yet attempt to parse out 2mg image format, and the question is open as
to whether or not I'll try to follow cppo's historical method of handling this
(chop the header and go), AppleCommander's method (consider 2mg its own unique
image format which happens to contain one of the others) or CiderPress's (use
one of several possible wrappers independent of the image orders.  CP's is
probably the most flexible.

So basically this code is probably far from final, but it works for what it
does so far.
2017-07-03 05:13:55 -07:00
T. Joseph Carter f3b5fe7dcd Added hexdump function
What's wrong with b2a_hex() or hex()?  Well, hex() only converts integers.  And
while a2b_hex() ignores whitespace, b2a_hex() doesn't provide any, making for
difficult to read output for anything longer than about 8 bytes or so.

In the basic case, it seems like you want a classic hexdump.  I chose the xxd
format:

xxxxxxxx: xxxx xxxx xxxx xxxx  xxxx xxxx xxxx xxxx |cccccccccccccccc|

Rather than hardcode all of the integers and strings (as I started doing), I
decided that I might as well use variables for these things if only for
readability.  And if they're locals, you might as well be able to override
them.

The knobs you have to play with are therefore these:

- wordsize=2, how many bytes are grouped together
- sep=' ', the spacing between words
- sep2='  ', the midpoint spacing

I suppose I could've made everything else configurable too, but YAGNI.
2017-07-02 15:45:28 -07:00
T. Joseph Carter 490d7e8224 Move 2mg parsing further down
This codebase is rapidly getting to the point it's going to need modules and a
package.  Let's move some logically related code for that purpose.
2017-07-02 15:41:24 -07:00
T. Joseph Carter c20adbabfb First move toward Disk class w/ a2mg data
Finally!  The Disk class doesn't actually serve as much more than a slightly
improved Globals class at the moment holding every splitting of the source path
and filename that we use in legacy code, as well as a copy of the disk image
itself that gets used long enough to read the a2mg header.

The idea I have here is to begin building the module-based code in parallel.
Then I'll just modify the linear code to compare doing it the old way to doing
it the new.  That'll let me verify that the new code does what the old should.

When it's all done, we can just modify main to use the new modular code and
look at splitting the modular code into a package with cppo as a runner.  At
that point the code should begin being able to do things cppo cannot.  We could
continue to extend cppo at that point, but my inclination is to maintain the
cppo runner as a compatibility layer and begin building a more modern image
tool.  Essentially to begin building the CiderPress for Linux or the Java-free
AppleCommander.
2017-07-01 03:45:53 -07:00
T. Joseph Carter 551ffa0496 Style fix (operator whitespace) 2017-06-30 15:13:52 -07:00
T. Joseph Carter 23392b77de Use struct.{un,}pack_into instead of int methods
The methods int.to_bytes() and int.from_bytes() are ... both messy and ugly,
contrary to the Zen of Python.  Right now, we're just writing out single ints
and words, but eventually we'll be reading and writing whole structures, so it
makes sense to begin moving the codebase in that direction.

I've written only the functions I either use or see a use for immediately, save
for pack_u32be() which I wrote for date conversions, and then immediately
realized we don't want to use for that purpose yet.  We can remove it if we
don't ultimately need it.
2017-06-30 14:30:31 -07:00
T. Joseph Carter e2d5e63a75 Spacing change 2017-06-30 02:50:32 -07:00
T. Joseph Carter 12c8ac0963 Readability counts (mostly whitespace)
There's a few magic constants in cppo that should become constants.  The one
for the Apple Epoch offset from the UNIX Epoch now is.
2017-06-26 06:56:19 -07:00
T. Joseph Carter 1e7e53c26d Logging, unStudlyCapping, main()
Replaced some of the commented out print lines with calls to a logger object.
These are currently always turned on, which we don't want, but they don't hurt
anything and are short.

Oh, and new logging system!  The setup is a bit more verbose than it could be
because logging predates str.format and uses the str % tuple syntax that now
exists mostly to avoid breaking older code.  You can override this, and I did.
It's not done yet because we might want to actually make some of the existing
print calls into log.info's.  Y'know, just as soon as I set that up so ONLY
logging.INFO goes to stdout, unadorned, and everything higher than that goes to
stderr, depending on your logging level, with pretty formatting.

Yeah, logging can do all of that and chew bubblegum at the same time, I just
haven't set it up yet because I want to do it right.

A little more unStudlyCapping of things.  I'm going to have to start actually
creating classes soon which is going to bring back the capitals, but I've been
working to get rid of them so that it becomes less confusing when we get there.
I dunno if it's helped any.

I also added a few comments about our imports and checked that we actually used
everything we imported.  No, we don't.  But we maybe should switch what we are
using for what we aren't at some point?
2017-06-26 05:35:46 -07:00
T. Joseph Carter 3935bcee50 Clean up time functions a bit 2017-06-25 16:15:39 -07:00
T. Joseph Carter eb0deff4d8 Rewrote pdosDateToUnixDate as date_prodos_to_unix
Function now takes raw bytes containing two little-endian 16-bit words right
out of a disk image.  It extracts timestamp components using bit shifting and
bitwise operators and asks datetime.datetime to give us a timestamp from the
result.  Caller need not catch exceptions for this process anymore.  Either it
works or you get None back.
2017-06-25 02:47:20 -07:00
T. Joseph Carter 63784d7b68 Remove bashbyter, misc cleanups, a bugfix
The full summary:

**ADDED**

 - New dopo_swap swaps 140k images between DOS order and ProDOS order.  This
   function replaces code in the main program body which does the same thing.
 - Add optional zfill parameter to to_bin.  Considered this for to_hex, but
   nowhere would that be used currently and I'd rather get rid of these lower
   level support functions that mainly are there for Bashbyter (but for now
   have larger direct use now that Bashbyter is gone.)

**CHANGED**

 - In getFileLength for DOS 3.3 T/other files, initialize prevTSpair to [0,0]
   which, when combined with the removal of Bashbyter and vestiges of Python2
   support, makes `The Correspondent 4.4.dsk` both -cat and extract.  (Noted
   previously, we currently do nothing about the control characters in the
   filenames on this disk.  They extract as non-printables and they don't show
   up properly in -cat.)
 - Replaced 4294967296 (2**32) with 1<<32 for use in turning negative integers
   into unsigned 32 bit integers.  It's possible to int.to_bytes() in a way
   that does this the way we want, and we ought to do that.  The syntax is
   longer than it needs to be though.
 - Strip high bit of DOS 3.3 filenames more efficiently
 - Replaced type("".encode().decode()) with str.  That wasn't necessary, and
   you might think otherwise is an example of why dropping Python 2 is a very
   good idea.
 - Use int.from_bytes() calls to replace reading several bytes by hand,
   multiplying them by bit offsets, and adding them together.
 - Made unixDateToADDate return four bytes instead of a hex-ustr because it
   only had one caller which just converted the value to that format anyway.
 - Misc slight changes like unStudlyCapping identifiers, saving a return value
   rather than calling the function that creates it multiple times, tuple
   assignment, and coding style

**REMOVED**

 - slyce functions: {,bin_,dec_,hex_}slyce
 - aToB conversions: binTo{Dec,Hex}, charTo{Dec,Hex}, decTo{Char,Hex},
   hexTo{Bin,Char,Dec} (just use to_thing or do it better than that.)
 - Removed: readchar{s,Dec,Hex}, writechar{s,sHex,Dec,Hex}
2017-06-24 03:22:26 -07:00
T. Joseph Carter 79719bb5e0 Change how case folding is done
The old way involved a lot more sequence duplication.  Now just turn the
bytes object into a mutable bytearray, iterate through the mask and
change what we need, then change it back.
2017-06-22 04:37:34 -07:00
T. Joseph Carter 3ebf568a6f More syntax cleanups
A few clumsy if statements got rewritten with truth tables to verify
that the somewhat simplified conditions still evaluated the same.  Other
changes are mostly cosmetic.
2017-06-22 04:17:23 -07:00
T. Joseph Carter e305008645 unStudlyCaps globals, make bools actually boolean 2017-06-22 04:05:36 -07:00
T. Joseph Carter 3a3531514b Protect main program with __main__ test
Originally cppo was written as a shell script and was never intended to
be a library of functions to be used by anyone else.  Single-file Python
modules are often written to be run as standalone programs either to do
what they do from the command line or for testing purposes.

Theoretically you do this if your code provides useful stuff for other
programs to use, and it's hard to argue that cppo does that yet, but it
is intended to do so in the future.  Let's start working toward that.
2017-06-22 01:59:07 -07:00
T. Joseph Carter 1d1eed33d2 Some diff reduction and renamed variables
A few of my local copies of cppo have some/most of the code reformatted
in a more "pythonic" coding style.  I still use hard tabs for
indentation because even us diehard console-using developers have
editors that can have whatever tabstop we want on a per-file basis, and
we have editorconfig.  It's 2017, get with the times, even for a program
made for accessing files for a 1977 computer!  ;)  No functional changes
here, save for an if statement processing extensions replaces multiple
conditionals with an if x in tuple construct.
2017-06-22 01:33:40 -07:00
T. Joseph Carter 3129db5989 Remove a couple needless slyce's 2017-06-21 22:23:39 -07:00
T. Joseph Carter a496c6bc0f Reformat arg parsing, add sli() function
Python's native sequence slicing method calls for start with optional
stop and step.  This is sometimes exactly what you want, but especially
when parsing binary files, you're gonna want start/length instead.  If
start was an expression, messy.

In cppo, there's a function slyce that returns a sliced sequence using
start/length/step metrics, and this is used exclusively for slicing
sequences.  Except sometimes you really want Python's start/stop...

I figure: Let's do it Python's way with the slicing syntax, but instead
of seq[start:start+length], you can use sli(): seq[sli(start,length)].
It's not currently used that way, but it now can be.  :)
2017-06-21 06:20:46 -07:00
T. Joseph Carter 795694dbb2 Add to_sys_name() to replace the win32 tests
A holdover from DOS 8.3 filenames, files on Windows cannot end with a
dot.  We append a - to such names on Windows platforms in all
operations, which should solve the problem, but we'd just duplicated
that code about a dozen times.  No need, do it once and we can add
whatever filesystem rules for the host system we need to in one spot.
2017-06-21 05:50:22 -07:00
T. Joseph Carter 54c91f70da Improve arg tests, optimize filename splitting
Lots of places want to check the extension, let's extract that just
once, and save the intermediate products so we can reuse those too.
2017-06-21 05:41:29 -07:00
T. Joseph Carter d94b45dbcc Fix some "else: pass" blocks for debug prints 2017-06-20 19:49:40 -07:00
T. Joseph Carter 567f1f2a8b Make cppo require python3 2017-06-20 19:48:22 -07:00
T. Joseph Carter 8254fd886d Remove unused get_object_names() 2017-06-20 19:47:06 -07:00
T. Joseph Carter 66df732b6e Remove unused shift() 2017-06-20 19:46:28 -07:00
T. Joseph Carter 7b71f597fc Remove unused s() 2017-06-20 19:45:43 -07:00
T. Joseph Carter 3e816f8299 Fix imports 2017-06-20 19:43:29 -07:00
T. Joseph Carter fb07295e6c One of many versions of cppo I've got around here
This one's missing a lot of the cleanups I've done to the others (it
isn't even python3), but it has the debug print statements and the
formatting is generally pretty good.  I'll go through my local trees and
begin applying some fixes to this code in various repositories and we'll
see if we can't begin refactoring it completely.
2017-06-20 19:27:38 -07:00