CNAME file not being copied to root output when publishing Pelican blog - python

I am following Tip #2 from the Pelican documentation to utilize a custom domain on GitHub pages. For this to work correctly, the CNAME file needs to be at the root of my site.
From the doc:
To use a custom domain with GitHub Pages, you need to put the domain of your site inside a CNAME file at the root of your site. To do this, create the content/extra/ directory and add a CNAME file to it. Then use the STATIC_PATHS setting to tell Pelican to copy this file to your output directory. For example:
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
I have done this. My pelicanconf.py has the following two settings:
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
I have created my CNAME file and placed it in content/extra/CNAME, as described in the documentation.
I publish the application like this:
pelican content --output output --settings pelicanconf.py
This generates my site in the output directory. The pages are all set up correctly. However, CNAME is not at the root. Instead it is at the extra/CNAME location.
I receive no errors or warnings when publishing. If I publish with the --debug parameter, this line appears in the output:
-> Copying H:\mysite\content\extra\CNAME to extra/CNAME
This clearly shows that it's copying it to extra instead of the root. According to the documentation, I've set my STATIC_PATHS and EXTRA_PATH_METADATA correctly to copy this to the root. How do I change my settings so that CNAME is copied to the correct location instead of the extra directory?

maggick was correct in his assessment in the comments.
Could this be a Windows related problem?
There is one tiny mention in the basic settings overview
Extra metadata dictionaries keyed by relative path. Relative paths require correct OS-specific directory separators (i.e. / in UNIX and \ in Windows) unlike some other Pelican file settings. See Path metadata.
(emphasis is mine)
This tidbit of information isn't mentioned in the Path metadata documentation or in the tips, both of which I'd been utilizing.
My solution, since I am running this on Windows, is to change:
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
to:
EXTRA_PATH_METADATA = {'extra\CNAME': {'path': 'CNAME'},}
^ This is OS specific
Notice the single changed slash in the dictionary key.

Strange this behavior. The docs clearly mention that even in windows you need to use forward slashes.
From readthedocs Pelican 3.6.4 - latest release
STATIC_PATHS = ['images', 'extra/CNAME']
EXTRA_PATH_METADATA = {'extra/CNAME': {'path': 'CNAME'},}
Note: use forward slashes, /, even on Windows.
But this solution works.

Related

How to change the name of the streamlit app page?

I have a web application deployed to Heroku. In the address line of the application, the name of the running file and the designation of the streamlit. How can I change this line with integer. Maybe you need to add some kind of configuration file?
I need to change the line "dashboard . Strealit"
Additionally, I ran into the fact that I have no application theme settings.
How can I enable them?
There is also a question about configuration files. They are located along the path: /.streamlit/
but if I place the code on GitHUB, then where should these files be located, in particular the file config.toml??
A few questions here. To change your page name, you can set that a the beginning of your app code with:
st.set_page_config(
page_title="My Page Title",
)
Streamlit theming was added in a recent update. To update your version and see the theme in the settings, you can run:
pip install streamlit --upgrade
and make sure to save the new version number in your requirements.txt.
Your're right, the config.toml file should be located inside a directory called .streamlit at the root of your app. You would need to commit that directory to your Github repo along with the rest of your files. Other config files, like editor configs, .gitignore, etc should be at the root of your project as well and can be committed with everything else.
Your problem is solved using st.set_page_config().
Streamlit has this attribute to change page title, page icon (favicon),layout, initial sidebar state, sidebar menu items.
Please check the Streamlit documentation answering your query from here,
st.set_page_config.
Use this code at the top of your streamlit_app.py file (if it has your main function)
st.set_page_config(page_title = "New Name")
Regarding the second question,
Use this code in setup.sh file, when ran in the Procfile this will create a dir with the theme configuration set in the config.toml under .streamlit directory.
mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"your-email#domain.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[theme]\n\
base='light'\n\
primaryColor='#3a70ec'\n\
backgroundColor='#FFD600'\n\
secondaryBackgroundColor = '#F0F2F6'\n\
textColor='#0e1862'\n\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
You may also checkout this answer on the second question,
https://stackoverflow.com/a/67001757/12007117
Thanks, upvote if found helpful!😊
You can change the app name, logo, etc. You should write the below code at the beginning of your script.
import streamlit as st
from PIL import Image
image_directory = "C:\\Users\Documents\logo.PNG"
image = Image.open(image_directory)
PAGE_CONFIG = {"page_title":"MyApp",
"page_icon":image,
"layout":"centered",
"initial_sidebar_state":"auto"}
st.set_page_config(**PAGE_CONFIG)

How to set the content type header in response for a particular file type in Pyramid web framework

I am using pyramid web framework to build a website. I keep getting this warning in chrome console:
Resource interpreted as Font but transferred with MIME type application/octet-stream: "http:static/images/fonts/font.woff".
How do I get rid of this warning message?
I have configured static files to be served using add_static_view
I can think of a way to do this by adding a subscriber function for responses that checks if the path ends in .woff and setting the response header to application/x-font-woff. But it does not look like a clean solution. Is there a way to tell Pyramid to do it through some setting.
Pyramid uses the standard mimetypes module to guess the mimetype based on the extension. It calls:
mimetypes.guess_type(path, strict=False)
The module looks in the Windows registry if on that platform, and in the following locations for mimetype lists:
knownfiles = [
"/etc/mime.types",
"/etc/httpd/mime.types", # Mac OS X
"/etc/httpd/conf/mime.types", # Apache
"/etc/apache/mime.types", # Apache 1
"/etc/apache2/mime.types", # Apache 2
"/usr/local/etc/httpd/conf/mime.types",
"/usr/local/lib/netscape/mime.types",
"/usr/local/etc/httpd/conf/mime.types", # Apache 1.2
"/usr/local/etc/mime.types", # Apache 1.3
]
You can either extend one of those files, or create your own file and add it to the module using the .init() function.
The file format is simple, just list the mimetype, then some whitespace, then a space-separated list of extensions:
application/x-font-woff woff
Simply add this following code where your Pyramid web app gets initialized.
import mimetypes
mimetypes.add_type('application/x-font-woff', '.woff')
For instance, I have added it in my webapp.py file, which gets called the first time the server gets hit with a request.

Installing a CGI Proxy on Tomcat

I want to setup a proxy for openlayers to use so I followed these steps:
Downloaded the proxy.cgi file from the OpenLayers web site:
http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi
Modify the proxy.cgi file to include my domain in the allowedHosts list:
allowedHosts = ['localhost:6901']
Copy the proxy.cgi file to the following folder:
$TOMCAT_PATH$/webapps/yourApp/WEB-INF/cgi/
Modify the file web.xml of your web app by adding the sections below. You find the file at
$TOMCAT_PATH$/webapps/yourApp/WEB-INF/web.xml
Comment: In case the web.xml file doesn’t exist for your webapp, just create it yourself or copy it from another webapp and modify it. (created!)
Comment: the “param-value” for the “executable” parameter has to contain the path to your Python installation. (it does!)
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>c:\python25\python.exe</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
Modify the file context.xml of your web app by adding the element below. You find the file at $TOMCAT_PATH$/webapps/yourApp/META-INF/context.xml
Restart Tomcat
To use the proxy with OpenLayers, just include this single line into your code:
OpenLayers.ProxyHost = "/yourWebApp/cgi-bin/proxy.cgi?url=";
But when I try to use it like:
/webappname/cgi-bin/proxy.cgi?url=labs.metacarta.com
I get this error:
Some unexpected error occurred. Error text was: list index out of range
I think its related with os.environ["REQUEST_METHOD"] but I dont know how its related ..
You're asking for an environment variable that isn't defined.
You need to either catch and handle the exception or use os.environ.get:
try:
methodq = os.environ["REQUEST_METHOD"]
except KeyError:
methodq = "default value"
Or:
methodq = os.environ.get("REQUEST_METHOD", "default value")
You're submitting :
/webappname/cgi-bin/proxy.cgi?url=labs.metacarta.com
But the proxy.cgi script is trying to do this:
host = url.split("/")[2]
Try http://labs.metacarta.com for your url so proxy.cgi has some slashes to split on, or modify it to parse the url a little smarter.
The answer is: You don't install or use cgi proxy on Tomcat.
cgi is for apache server or IIS that are used as a front-end server. Tomcat may sit behind it. The configuration of Apache is detailed in: http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html
Be warned that OpenLayers warns that its proxy.cgi is only an example and may not have good enough check to stop it from being exploited, i.e. it may run some malicious script.
If you are serving your OpenLayers client page on Tomcat alone and it contains layers from other GeoServer or Mapserver, you can use proxy servlet and specify it as:
OpenLayers.ProxyHost = "sevlet URL on the server that served this page";
http://wiki.apache.org/tomcat/ServletProxy
https://svn.openxdata.org/Experimental/openXmapper/trunk/gwt-openlayers-server/src/main/java/org/gwtopenmaps/openlayers/server/GwtOpenLayersProxyServlet.java
There are reverse proxy or rewrite sevlet solutions to it, too. Please Google on these.

tarfile and user,group information problem

I am using python tarfile module to extract files from a *.tgz file. Here what I use:
import tarfile
tar = tarfile.open("some.tar")
tar.extractall(".")
tar.close()
Assume "some.tar" contents as:
-a.txt ===> user:usr1 , group: grp1
-b.txt ===> user:usr2 , group: grp2
But after extracting I lose all of user,group,date... information. They now belong to whoever calls the script(in my case root). They become like:
-a.txt ===> user:root , group: root
-b.txt ===> user:root , group: root
Is there a way to keep file owner,date information of files?
From tarfile module page:
-handles directories, regular files, hardlinks, symbolic links, fifos, character devices and block devices and is able to acquire and restore file information like timestamp, access permissions and owner.
From this statement I understand that is is very well possible to do this by "tarfile" module, or do I understand it wrong?
Python version is 2.6.1
Edit: I am running this script as root
Thanks
As guettli says, you have to be root to be able to change the ownership of a file to somebody else. Otherwise, you open a huge security hole. This is true when using the tar(1) program or when trying to use the tarfile package from python.
Note, though, that some earlier version of Python have a bug (see issue in comments below) that means files extracted by root are owned by root instead of the real owner (user and group).
First, your script needs to run as root (on unix like systems). Otherwise, you can't use chown.
You need to get the TarInfo object for the files:
http://docs.python.org/library/tarfile.html#tarfile.TarInfo
There you get uid (user id) and gid (group id) and (or user name).
Then you need to use chown.

Hide password when checking config file in git [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
What is the best practice for dealing with passwords in github?
How can I track system-specific config files in a repo/project?
Hi,
I would like to hide
DATABASE_NAME = ''
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
Line 13 to 17 of the default Django settings.py file when checking it in github.
I still want to check it in tho, because I am adding modifications from time to time. I just want these four lines to always be set to empty.
You could also have an extra settings file which holds passwords and just import them in your main settings.py
For example:
settings.py
DATABASE_PASSWORD = ''
try:
from dev_settings import *
except ImportError:
pass
dev_settings.py
DATABASE_PASSWORD = 'mypassword'
And keep dev_settings.py out of revision control.
For my configuration files, I create a config.py-example and a config.py. config.py is ignored by the version control. When I deploy, I just copy config.py-example to config.py and update the passwords.
Unfortunately, that's not how Git works - either a file is in version control, or it isn't.
If you don't want the info in Github, then don't check it in. You could keep a copy of the config file in a separate (private) repository elsewhere if you wanted, though.
I would recommend keeping settings.py with those four lines exactly as you've shown them, and have a separate, tiny Python script to add and remove the four bits of secret information (reading them from a file that's not part of your git repository, but rather is safely and secretly kept -- in a couple of copies, for safety -- in very secure places).
You can have a presubmit check to make sure you never, ever push a settings.py that has not been shorn of the secrets (I don't know git enough to tell if it has "presubmit triggers" that can modify the repo, as well as presubmit checks that just check it, but, if it does, then clearly it may be more convenient for you to use said tiny Python script in such a trigger -- indeed, if that's the case, you might want to consider doing the removal/restoring of the secrets by using patch, and a simple diff file to use as its input, so you don't have to write even a line of script for the purpose).

Categories