Provide a bunch of utilities for soypak.
Specify compiled regexes for bottle file parsing.
func@ensure_dir:
- Will ensure that a directory that exists, and if it doesn't, will
create it and any parents. Mode is 0755.
- From DNF util module.
func@join_path:
- Will join any number of string paths together and return a new
string path.
- From eopkg util module.
func@rack_bottle:
- Function will aim to write a new bottle file out to the database
(nickname: rack).
- Either a string representation of a bottle file can be given, or a
file descriptor of type TextIOWrapper, can be given as the file
pointer:
- if a TextIOWrapper, ensure that the pointer is at the start of
the file to read the contents again.
- if a string, the contents can be set at this.
- Detect if there are any comments (useful from translating user
defined bottles to be stored - Packages file won't have this). If
so, remove them.
- Ensure that the database rack exists.
- Create the new filename to be stored.
- Attempt to open the file in write mode and write the contents to
file. Report on the amount of bytes written for clarity.
- Function returns true if the file was successfully racked. False
upon any failures.
Parse bottle files and constructure a package class which can be used in
transactions.
Set of valid packages keys is defined.
func@_parse_bottle_file:
- Module protected function called internally to parse bottle files.
- Extract the Description field (this is a little different from
other fields given it can be multiline).
- Remove any comments which may have been left by a user.
- Process the bottle file and extract all key-value pairs. This will
also ensure that mandatory fields exist, and that any fields which
are repeated are flagged (parser will cause app to crash).
- Return a dictionary of key-value pairs.
class@_Soybottle:
- Class (struct) which represents a bottle file in a structured
format. The dictionary is unwrapped after parsing and populates
this class using the `.loadPackage()` classmethod.
- Defined repr dunder which will return a string representation of
the class as a dictionary (note class uses slots).
- method@loadPackage():
- Defines a set of mandatory fields required in the bottle file.
- Reports and exits if mandatory fields are missing. Warn if
unrecognised fields exist.
- Separate optional fields from mandatory ones.
- Construct new class instance and return the object.
class@PackageItem:
- Class which stores information regarding a package, including
whether it is installed, and the package information from
_Soybottle. Class is early development.
func@loadPackage:
- This function is akin to _Soybottle@loadPackage, but *should* be
called instead of the classmethod. To be called when a bottle file
is given as argv, not by bottle file in the database.
- Given a filename (`item=`), will attempt to open and read the
contents of a bottle file. If the file is readable, it will then
begin parsing and constructing a new class@PackageItem object.
- Function will attempt to permanently store a bottle file to
database. If this fails, the app will sys-exit.
- Either the class@PackageItem or Exception is returned. This is to
allow for exception messages to be given back to the install
command.
Now uses transaction module.
Conditional statement changed for checking if an argv is a bottle file:
- Initially check for file suffix. Inform if file detected.
- Then check if bottle file exists on the system. Report
accordingly.
- Attempt to load the bottle file as a package. Fail if otherwise
unable to do this. Otherwise inform that it was loaded okay.
Check if we have anything to install. Inform and exit if we have
nothing.
Start a new transaction:
- This is to give greater control and ensure the goal is met. A
transaction is initialised with a goal, and `.apply()` will
perform this goal.
- Compute the system dependencies with `.compute()`. Any
dependencies which soypak can install (recognised in the packages
database), will not be included here. Report if we have
dependencies.
- Apply the transaction to the system with `.apply()`. This will be
dependent on the goal set.
- Check for problems when applying the transaction with `.problems()`.
- Finally commit the transaction to record.
- Added global variable for logging.
- Removed `class@RegisterCommand` metaclass.
- Replaced with decorator function.
- Added `class@CommandHelpStruct`.
- Basic struct to define rigid structure of the help message of a
command. Uses `__slots__` over instance dictionary.
- Changed type annotations for removal of metaclass.
- Added logging.
- Created decorator function `register_command()`.
- Used to register a new command class (replaces metaclass)
- Guarantees a name and doc dunder attribute is defined.
- Registry now ensures that a command isn't already defined with the
same registry name.
- Must be invoked with parens
Added implementation to run command. For every argument give (a
command), the help message for that command is displayed.
Renamed `__cmd_name__` to `name`, which will be standard across all
commands.
Command@get_command() method now allows for the app to error if a
command is unrecognised. This is used by commands such as Help, when a
help message cannot be displayed for an unrecognised command.
Changed the way help summary messages are accessed from commands.
soypakcli is responsible for registering all commands, parsing and
invoking the command to run.
- global optional flags are explicitly check first, regardless of the
number of args.
- if there is no command, the program displays the help message and
dies.
- fetches the command class for the identified soypak command and
initialised the class command.
- SoypakCLI@run_command: invokes the `run()` method of a command class
- Changed class@SoypakParser => class@_SoypackParser
- class@SoypakParser is now a singleton pattern which handles
class@_SoypakParser.
- SoypakParser@add_action_command (static method): add a command to the
action group (argparser).
Added the soypak help command. When called, it will provide the user
with help information about the soypak command(s) provided as arguments.
- Implements a `__doc__` attribute with summar and usage.
- Overrides the `run()` method from `Command` when inherited.
- Inherits `command.Command` and metaclass `RegisterCommand`.
Module is responsible for allowing the creation, registering and
initilisation of soypak commands.
Added class@RegisterCommand:
- used by command classes as a metaclass. Will be auto-invoked upon
the class' declaration.
- checks if a command is registered already with an existing name.
- uses the class' `__doc__` attribute to register an entry on the
help display message with name and summary.
Added class@Command:
- Inherited by command classes.
- Keeps record of the registered commands and the instance of the
class which can then be invoked during `get_command()`.
- Command@get_command (static method): find and return an
initialised instance of a command that has been registered.
Otherwise return `None`.
- Command@run (virtual): to be implemented on a child class of
`Command`.