Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions preprod/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from datetime import datetime
__version__="1.3.0"
__versiondatetime__= datetime(2025, 3, 13, 10, 3)
__versiondate__=__versiondatetime__.date()
from .version import __version__, __versiondate__, __versiondatetime__
from .commons import epilog
9 changes: 9 additions & 0 deletions preprod/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from subprocess import run, Popen, PIPE
from time import sleep as time_sleep
from sys import exit, stdout
from .version import __version__, __versiondate__




"""
Each command should have these parameters
Expand All @@ -22,6 +26,11 @@
except:
_=str

def epilog():
"""
Generates the epilog string for the argument parser, including version information.
"""
return _("Developed by Mariano Muñoz {}-{}").format(__versiondate__.year, __versiondate__.year)


def red(s):
Expand Down
31 changes: 20 additions & 11 deletions preprod/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
from gettext import translation
from importlib.resources import files
from multiprocessing import Lock
from os import path, makedirs
from preprod import commons
from os import path, makedirs, system
from . import commons, __version__, __versiondate__
from sys import exit
from preprod import __version__, __versiondate__
from getpass import getuser
from os import environ # For EDITOR environment variable
from shutil import which # For checking editor availability

try:
t=translation('preprod', files("preprod") / 'locale')
_=t.gettext
except:
_=str

def argparse_epilog():
"""
Generates the epilog string for the argument parser, including version information.
"""
return _("Developed by Mariano Muñoz {}-{}").format(__versiondate__.year, __versiondate__.year)

def concurrent_log(title, stdout=None, stderr=None):
"""
Expand Down Expand Up @@ -57,9 +53,10 @@ def main(arguments=None):
lock=Lock()

global args
parser=ArgumentParser(description=_("Preprod manager"), epilog= argparse_epilog())
parser=ArgumentParser(description=_("Preprod manager"), epilog= commons.epilog()) # Corrected epilog call
parser.add_argument('--version', action='version', version=__version__)
parser.add_argument('--pretend', default=False, help=_("Prints action code without running it"), action='store_true')
parser.add_argument('--edit', default=False, help=_("Opens the action file in the default console editor"), action='store_true')

parser.add_argument('project', nargs='?', default=None, help=_("Project identification"), action='store')
parser.add_argument('action', nargs='?', default=None, help=_("Action identification"), action='store')
Expand Down Expand Up @@ -93,6 +90,19 @@ def main(arguments=None):
print(commons.red(_("Project '{0}' hasn't '{1}' action. Found actions: {2}").format(args.project, args.action, commons.green(str(dpa[args.project])))))
exit(4)

if args.edit:
editor_command = environ.get('EDITOR')
if not editor_command:
if which('mcedit'):
editor_command = 'mcedit'
elif which('nano'):
editor_command = 'nano'
else:
editor_command = 'vi' # Fallback to vi if no other editor found or EDITOR env var not set

system(f"{editor_command} {action_path}")
exit(0) # Exit after editing

if args.project is not None and args.action is not None:
start=datetime.now()
with open(action_path) as f:
Expand Down Expand Up @@ -124,8 +134,7 @@ def create():
Creates the necessary directory structure and a sample project/action
along with a `repository_commons.py` file.
"""

parser=ArgumentParser(description=_("Preprod manager"), epilog= argparse_epilog())
parser=ArgumentParser(description=_("Preprod manager"), epilog= commons.epilog()) # Corrected epilog call
parser.add_argument('--version', action='version', version=__version__)
parser.parse_args()

Expand Down
5 changes: 5 additions & 0 deletions preprod/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from datetime import datetime
__version__="1.3.0"
__versiondatetime__= datetime(2025, 3, 13, 10, 3)
__versiondate__=__versiondatetime__.date()