Skip to content

Commit

Permalink
[UP] Start working with workspace resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Jan 26, 2025
1 parent ae98b04 commit a2268c7
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 16 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ python_requires = >=3.8
install_requires =
importlib-metadata; python_version<"3.8"
rich>=13.9.4
setuptools


[options.packages.find]
Expand Down
20 changes: 15 additions & 5 deletions src/otoolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import argparse


from otoolbox import administrator
from otoolbox import developer
from otoolbox import maintainer
from otoolbox.args import administrator
from otoolbox.args import developer
from otoolbox.args import maintainer
from otoolbox import env


Expand Down Expand Up @@ -58,6 +58,15 @@ def init_cli():
dest="verbose",
required=False,
default=0)


arg_parser.add_argument(
"--silent",
help="""Do not print extra information""",
action="count",
dest="silent",
required=False,
default=0)

return arg_parser, arg_parser.add_subparsers()

Expand All @@ -70,5 +79,6 @@ def init_cli():

args = parser.parse_args()
env.context.update(args.__dict__)
print(env.load_text_banner())
args.func()
if not env.context.get('silent', 0):
print(env.resource_string("data/banner.txt"))
# args.func()
Empty file added src/otoolbox/args/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
def run():
print("hello from otoolbox: develoepr")


def init_cli(parent_parser, **kwargs):

return parent_parser
File renamed without changes.
6 changes: 3 additions & 3 deletions src/otoolbox/developer.py → src/otoolbox/args/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
bridges the gap between development and operations, enhancing productivity and
ensuring a seamless development experience in Odoo projects.
"""
from otoolbox import common
from otoolbox.utils import develop
from otoolbox.args import common
# from otoolbox.utils import develop


def init_cli(parent_parser):
Expand Down Expand Up @@ -77,7 +77,7 @@ def init_cli(parent_parser):
dest='python',
action='store_false')

dev_init.set_defaults(func=develop.init)
# dev_init.set_defaults(func=develop.init)

# dev update
dev_update = dev.add_parser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
package offers a reliable and streamlined solution for maintenance operations.
"""

from otoolbox import common
from otoolbox.utils import admin
from otoolbox.args import common
# from otoolbox.utils import admin


def init_cli(parent_parser):
Expand Down
59 changes: 59 additions & 0 deletions src/otoolbox/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import logging

_logger = logging.getLogger(__name__)

class WorkspaceResource():
def __init__(
self,
path,
title = None,
description = None,
constructors = None,
destructors = None,
validators = None
):
self.path = path
self.title = title
self.description = description if description else []
self.constructors = constructors if constructors else []
self.destructors = destructors if destructors else []
self.validators = validators if validators else []

# internals
self.validation_errors = []
self.is_valied = False


class WorkspaceResourceGroup():
def __init__(self):
self.resources = []

def append(self, resource:WorkspaceResource):
self.resources.append(resource)
###################################################################
# constructors
###################################################################
def makedir(context):
pass



###################################################################
# validators
###################################################################
def is_readable(context):
pass

def is_dir(context):
pass

def is_file(context:WorkspaceResource):
pass



###################################################################
# destructors
###################################################################

3 changes: 3 additions & 0 deletions src/otoolbox/data/WORKSPACE_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Odoonix Toolbox

This is a maintainer tool from odoonix
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 34 additions & 1 deletion src/otoolbox/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""Envirnement fo the sysetm"""

import pkg_resources
import os
import sys
from otoolbox import base

VERSION = "0.0.0"
context = {}
context = {
'resources': {}
}




def load_text_banner():
Expand All @@ -25,3 +32,29 @@ def resource_stream(resource_name):
def get_workspace():
"""Get the workspace"""
return context.get("path", ".")

def get_workspace_path(path):
"""Gets subfolder/file with in workspace"""
return os.path.join(get_workspace(), path)



#################################################################################
# Resource
#################################################################################
def add_resource(resource:base.WorkspaceResource):
group = context['resources'].get(resource.path, None)
if not group:
group = base.WorkspaceResourceGroup()
group.append(resource)
return sys.modules[__name__]

def constructor_copy_resource(path):
"""Create a constructor to copy resource with path"""
def copy_resource(resource:base.WorkspaceResource):
resource_stream = resource_stream(path)
# Open the output file in write-binary mode
with open(resource.path, 'wb') as out_file:
# Read from the resource stream and write to the output file
out_file.write(resource_stream.read())
return copy_resource
31 changes: 31 additions & 0 deletions src/otoolbox/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from otoolbox import env
from otoolbox import base
from otoolbox.base import WorkspaceResource








###################################################################
# init
###################################################################
(env
.add_resource(WorkspaceResource(
path=env.get_workspace_path("README.md"),
name="Workspace README",
description="A readme that shows parts of the workspace",
constructors=[
env.constructor_copy_resource("data/WORKSPACE_README.md")
],
destructors=[
base.delete_file
],
validators=[
base.is_file,
base.is_readable
]
))
)

0 comments on commit a2268c7

Please sign in to comment.