web.py, How to share the base_base_template among subapps? - web.py

In order to reduce the superfluous codes,I want to share a base template among many
subapps,
Example dir tree
├── admin
│   ├── __init__.py
│   ├── templates
│   │   └── admin.html
│   └── view.py
├── base_templates
│   └── base.html
└── view.py
Now , I am using dir package styel as a sub app(I dunno whether it's a right way to do this). Above,
I am going to use base.html template in admin app, so
foo.py
render = web.template.render(...) # the render
class Foo:
def GET:
return render.admin()
any way to resolve my trouble ? thx

You can do this using a site layout template.

Related

Using GitHub Actions in a Single Repository with Multiple Projects

I am fairly competent in using GitHub actions to build a variety of languages, orchestrate deployments, and I've even done cross-repository actions using web-hooks, so I'd say that I'm pretty familiar with working with them.
I often find myself doing a lot of scratch projects to test out an API or making a demo, and these don't usually merit their own repositories, but I'd like to save them for posterity, rather than just making Gists out of them, Gists being largely impossible to search. I'd like to create a scratch repository, with folders per language, like:
.
└── scratch
├── go
│   ├── dancing
│   │   ├── LICENSE-APACHE
│   │   ├── LICENSE-MIT
│   │   ├── main.go
│   │   └── README.md
│   ├── gogettur
│   │   ├── LICENSE-APACHE
│   │   ├── LICENSE-MIT
│   │   ├── main.go
│   │   └── README.md
│   └── streeper
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── main.go
│   └── README.md
├── node
│   └── javawhat
│   ├── index.js
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   └── README.md
└── rust
├── logvalanche
│   ├── Cargo.toml
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── README.md
│   └── src
├── streamini
│   ├── Cargo.toml
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── README.md
│   └── src
└── zcini
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
└── src
I'd like to generalize GitHub actions per language, for Go, use go test ./... and go build, for Rust cargo test and cargo build, etc.
I know that what I could do is have a workflow for each created project, but this would be tedious, I'd end up copying and pasting most of the time, and every build would run on every change in the entire repository, and I don't want to be building node/javawhat if only rust/zcini has changed.
Therefore I have a few questions:
Is it possible to have a workflow only run when certain files have changed, rather than running everything every single time?
Is there a way to generalize my workflows so that every dir in rust/ uses the same generic workflow, or will I need one workflow per project in the repository?

Importing json resources inside .pex (Python Executable (format by Twitter))

I'm using a Twitter engineered build tool pants to manage many projects inside my monorepo. It outputs .pex files when I complete a build, this is a binary that packages the bare minimum dependencies I need for each project and makes them a "binary" (actually an archive that's decompressed at runtime), my issue is a utility that my code has used for a long time fails to detect some .json files(now that I'm using pants) I have stored under my environments library. all my other code seems to run fine. I'm pretty sure it has to do with my config, perhaps I'm not storing the resources properly so my code can find it, though when I use unzip my_app.pex the resources I desire are in the package and located in the proper location(dir). Here is the method my utility uses to load the json resources:
if test_env:
file_name = "test_env.json"
elif os.environ["ENVIRONMENT_TYPE"] == "PROD":
file_name = "prod_env.json"
else:
file_name = "dev_env.json"
try:
json_file = importlib.resources.read_text("my_apps.environments", file_name)
except FileNotFoundError:
logger.error(f"my_apps.environments->{file_name} was not found")
exit()
config = json.loads(json_file)
here is the the BUILD file I use for these resource currently:
python_library(
dependencies=[
":dev_env",
":prod_env",
":test_env"
]
)
resources(
name="dev_env",
sources=["dev_env.json"]
)
resources(
name="prod_env",
sources=["prod_env.json"]
)
resources(
name="test_env",
sources=["test_env.json"]
)
and here is the BUILD file for the utility that calls these resources of which the python code above is what you saw:
python_library(
name="environment_handler",
sources=["environment_handler.py"],
dependencies=[
"my_apps/environments:dev_env",
"my_apps/environments:prod_env",
"my_apps/environments:test_env"
]
)
I always get an FileNotFoundError exception and I'm confused because the files are available to the runtime, what's causing these files to not be accessible? and is there a different format I need to set up the JSON resources as?
Also for context here is the decompressed .pex file(actually just the source-code dir):
├── apps
│   ├── __init__.py
│   └── services
│   ├── charts
│   │   ├── crud
│   │   │   ├── __init__.py
│   │   │   └── patch.py
│   │   ├── __init__.py
│   │   └── main.py
│   └── __init__.py
├── environments
│   ├── dev_env.json
│   ├── prod_env.json
│   └── test_env.json
├── __init__.py
├── models
│   ├── charts
│   │   ├── base.py
│   │   └── __init__.py
│   └── __init__.py
└── utils
├── api_queries
│   ├── common
│   │   ├── connections.py
│   │   └── __init__.py
│   └── __init__.py
├── calculations
│   ├── common
│   │   ├── __init__.py
│   │   └── merged_user_management.py
│   └── __init__.py
├── environment_handler.py
├── __init__.py
├── json_response_toolset.py
└── security_toolset.py
I figured it out: I changed the way I access the files within the library and it works perfectly before and after the build to .pex format. I used:
import pkgutil
#json_file = importlib.resources.read_text("my_apps.environments", file_name)
json_file = pkgutil.get_data("my_apps.environments", file_name).decode("utf-8")

Is there way to make links between files or directories on AEM-Assets?

I use AEM6.2 Assets.
Is there way to make links between files or directories without programing? (like symbolic link)
I want to make "assets/B/photos" in the following.
assets/
├── A
│   └── photos
│   ├── 01.jpg
│   └── 02.jpg
└── B
└── photos -> ../A/photos/

How to include images in a jekyll project hosted on github?

I'm building a blog using jekyll and hosting it on github with gh-pages. The root of my project can be see seen below:
├── LICENSE
├── README.md
├── _config.yml
├── _img
│   ├── 2016-09-09\ 14.48.20.png
│   └── 2016-09-09\ 15.25.09.png
.
.
.
├── _posts
│   ├── 2016-09-08-seven-weeks-before-applying-to-devops-job.markdown
│   └── 2016-09-09-an-hour-with-ansible.md
.
.
.
├── _site
│   ├── 2016
│   │   └── 09
│   │   ├── 08
│   │   │   └── seven-weeks-before-applying-to-devops-job.html
│   │   └── 09
│   │   └── an-hour-with-ansible.html
│   ├── LICENSE
│   ├── README.md
│   ├── about
│   │   └── index.html
│   ├── css
│   │   └── main.css
│   ├── feed.xml
│   └── index.html
├── about.md
├── css
│   └── main.scss
├── feed.xml
└── index.html
The documentation gives the following example:
Because of Jekyll’s flexibility, there are many solutions to how to do this. One common solution is to create a folder in the root of the project directory called something like assets or downloads, into which any images, downloads or other resources are placed. Then, from within any post, they can be linked to using the site’s root as the path for the asset to include. Again, this will depend on the way your site’s (sub)domain and path are configured, but here are some examples (in Markdown) of how you could do this using the site.url variable in a post.
Including an image asset in a post:
... which is shown in the screenshot below:
![My helpful screenshot]({{ site.url }}/assets/screenshot.jpg)
I've tried several different ways but non are working once I push gh-pages up:
![]({{ site.github.url }}/_img/2016-09-09 14.48.20.png)
![]({{ site.url }}/_img/2016-09-09 15.25.09.png)
I've also tried "keeping" the _img directory by putting the following in my _config.yaml
# Build settings
markdown: kramdown
keep_files: ["_img"]
But this also is not working. So how do I include images in a jeykll project hosted on github?
Thanks for your help :)
Every folder beginning with an underscore won't be copied to the build destination. The most common way is to store images is to add them to a assets/img folder.
If you want to use _img you have to add to your _config.yml:
include:
- "_img"
Create a folder for your images, you can name it according to your wish (mine is "images")
Find the image address of that image that you want to include in your post
(You can do that by going to your folder image and right click on your image, then copy image address)
Now you use that address in your post without any problem.

spring-security-facebook, s2-init-facebook not generating the Default Dao

I have installed spring-security-facebook to a test grail application. This was done after installing spring-security-core and running s2-quickstart.
I am just a novice and was trying to integrate the facebook login button into my test app. But, the problem is that when I run s2-init-facebook the plugin is not generating the default Dao as it was told in the documentation in http://grails.org/plugin/spring-security-facebook
Use your own authentication dao
Plugin generates an Dao, after calling s2-init-facebook#, and put it
into your #conf/spring/resources.groovy and #Config.groovy#. Actually
it's an 'dumb' dao implementations, you have to rewrite it to follow
your data structures:
The shortened tree output of my app directory is given below:
.
├── application.properties
├── grails-app
│   ├── conf
│   │   ├── ApplicationResources.groovy
│   │   ├── BootStrap.groovy
│   │   ├── BuildConfig.groovy
│   │   ├── Config.groovy
│   │   ├── DataSource.groovy
│   │   ├── hibernate
│   │   ├── spring
│   │   │   └── resources.groovy
│   │   └── UrlMappings.groovy
│   ├── controllers
│   │   ├── LoginController.groovy
│   │   └── LogoutController.groovy
│   ├── domain
│   │   └── com
│   │   └── fbtest
│   │   └── webapp
│   │   └── auth
│   │   ├── FacebookUser.groovy
│   │   ├── SecRole.groovy
│   │   ├── SecUser.groovy
│   │   └── SecUserSecRole.groovy
│   ├── i18n
│   │   ├── ...
│   ├── services
│   ├── taglib
│   ├── utils
│   └── views
│   ├── error.gsp
│   ├── index.gsp
│   ├── layouts
│   │   └── main.gsp
│   └── login
│   ├── auth.gsp
│   └── denied.gsp
├── lib
├── scripts
├── src
│   ├── groovy
│   └── java
├── test
│   ├── integration
│   └── unit
└── web-app
├── ...
resource.groovy file is also empty.
// Place your Spring DSL code here
beans = {
}
Please, help me in understanding if I am doing any thing wrong.
I am using Grails version: 2.0.4 and spring-security-facebook's version is 0.8.
Thanks in advance.
Oh, it should be removed from documentation. For last versions it's not necessary to have own DAO, now it have default very flexible dao. And now it's not generated during install. Try to run your app, it should works, if everything is configured correctly.
You can still use own DAO, if you have implemented it by yourself. But for versions since 0.7 nearly everything can be extending with optional FacebookAuthService, that you can implement if you wish (it's described in documentation as well).