I'm working on a project utilizing Django on Google App Engine. I've been asked if some of the code can be deployed as compiled only.
So I guess the question is can I upload a .pyc file only that contains the piece of code in question? I've done a basic test with a views.pyc file in an application and things don't work. Is there some configuration or other that I can set to allow Google App Engine to just use the .pyc files?
No, you can't - you can only upload sourcecode. There's no good reason to do this, though: your code will be bytecode-compiled on the servers when needed, and nobody is able to access your code in any case.
I realise you couldn't do this when you asked this question, but you can now, if you use Python 2.7. See Sandboxing in Python 2.7:
You can upload and use .pyc, but not in combination with .py files. You can upload zip files containing .py or .pyc files (or a combination).
Why would you want to do that in the first place? Because your .py files are uploaded to Google infrastructure and can be seen only if you explicitly give permissions.
But yes, there is no reason as why uploading only .pyc files should not work. If you try it, in your dev environment, you will find it working just as BaseHTTPServer can take python compiled modules as handlers.
Also, recent GAE supports automatic precompilation for python files, which means that as soon as you update your application, the python files can precompiled and served. So, you might have to play with --no_precompilation during appcfg.py upload if there was any expectation to check for .py files at the app engine end.
Related
This is more of an structural architectural question. I am using Python gettext module to fetch translations. But the way it works, as described in the link as well, the translations have to be in the same repo and pod with the Python code so that the gettext module can find them in the local directory when the application is running.
The issue with this is that we have to update and redeploy the repo every time the translations change. Would it be possible for gettext module to fetch the translation from cloud storage or even better maybe from a different pod which is deployed independently from the application? Any suggestions on how I can separate the code from the translations?
This is not possible out of the box.
But you can change the directory where .mo files are searched with gettext.bindtextdomain(). They don't have to be in the local directory, when the application is running.
I'm attempting to build an application that runs locally on a user's computer. It takes inputs and displays information, so I thought a nice way to make it work would be to have a Flask server that handles web forms, etc, to gather user input, and to display database contents in tables.
The service works when I run the Flask development server, and everything is fine and dandy, but I want to compile the entire project into a single executable file.
My questions are as follows:
Is it possible for me to have the flask server automatically start up and open the portal page when I double-click the EXE
Assuming this is a feasible concept, how would I go about compiling the exe? A brief look through the pyinstaller documentation does not tell me how I would compile a folder (which in this case would be more of a Python package), which would be a necessary pre-requisite considering that Flask has static and template folders containing my HTML, CSS, and JS files, not to mention the fact that my file tree is built in a modular manner.
Am I approaching this the wrong way? Would it be better to build a "launcher" application that runs Flask as a Windows service (vis a vis this question) instead of attempting to have an all-in-one EXE?
For reference, my file tree looks something like this:
Application
|_static
|_templates
|_\templates\errors
|_\templates\forms
|_errors
|_database
|_\database\connections
|_\database\iohandlers
|_"__init__.py"
|_"app.py"
While doing research on this, I came across this answer but as my situation doesn't mesh with the model that the OP had laid out, I thought it would be pertinent and useful to ask another question.
I want to access the folder /store/ariel/events/payloads/ in the Qradar directories from the App editor. I am trying the os.path.exists however it returns false however, the folder exists as well as the path is located if I run the script in the linux kernel of the Qradar. I would really appreciate if anyone can guide me on how to access the directories from the Qradar App Editor.
Can't do it, unfortunately.
In QRadar, Apps can only interact with the rest of the deployment via API calls.
The App Framework guide can provide some more details about what's available to App developers.
I have been experimenting with the Python Cloud Functions. One of my cloud functions utlizies a large text file, that I would love to bundle with my .py file when I deploy it. THe docs are kinda limited on stuff like this..
https://cloud.google.com/functions/docs/quickstart
I was looking, would I just include that file, and a requirements file in my same directory as my function to deploy it. Or do I have to some how require it in my code?
Also, is there any information on how to use a database trigger instead of a http trigger? I was trying to think if the reason my file didn't seem to get included was because I had the wrong way of defining the trigger. How would you create an OnCreate.. or something like that
gcloud beta functions deploy hello_get --runtime python37 --trigger-http
When you deploy your function using gcloud, your project directory is zipped and uploaded. Any files contained in the current directory (and child directories) will be uploaded as well, which includes static assets like your large text file.
Just make sure your text file is in your project directory (or one of the child directories), then use a relative reference to your file in your Python code. It should just work.
Following up on my last year's question on documentation, I now want to get started and try out Python-based Sphinx for putting together the developer documentation for a PHP CMS I've been working on.
Instead of setting up Python locally on my workstation, I would like to run it on a publicly accessible web server from the start. All the web hosting packages I have access to run on the LAMP stack, and I'm reluctant to buy Python-based hosting. I am very interested in the Google App Engine, the free quotas they provide will do for me a hundred times over, and even if not, their pricing looks very reasonable.
Now I have zero knowledge of Python - getting Sphinx to work would be my first contact with it - and very little time. As far as I understand, the platform and python libraries the App Engine provides are very compatible to a standard Python library but not identical.
So my question is:
Can Sphinx run on App Engine at all?
Is installing Sphinx on the App Engine as straightforward as if I would install it on top of a normal Python installation? Or will the App Engine's environment require tweaking of the source code that I can't perform in reasonable time with my current level of Python?
Should I be installing Sphinx on a local server and a "normal" Python stack instead first?
Does anybody know any helpful How-to's, tutorials or other resources for this?
You do not need to install Sphinx on GAE at all.
You use Sphinx to create a directory of static HTML, CSS and JS. When this step is finished, you simply upload the output from Sphinx -- in it's entirety.
The output from Sphinx (HTML, CSS and JS) is simply served from one place. You upload the documentation from where you created it to GAE as static files and serve them. Done.
There's no "install on a web server" aspect to Sphinx at all. Sphinx is not a web application; it does not run on your web server. You run it in development briefly to publish the documentation to HTML, LaTeX or whatever. Once you've created the static HTML files, you no longer need any part of Sphinx anywhere.
Can Sphinx run on App Engine at all?
I suppose it can, but you never need to.
Is installing Sphinx on the App Engine
as straightforward as...
It doesn't matter, because you don't install it there. You install it on your workstation and use it on your workstation.
Should I be installing Sphinx on a
local server and a "normal" Python
stack instead first?
Don't install it on a server. Install it on your workstation.
Does anybody know any helpful
How-to's, tutorials or other resources
for this?
If by "this" you mean "installing on a web server", then then answer is "no". One does not install it on a web server. So there are no how-to's, tutorials or resources for "installing on a web server".
If by "this" you mean "creating documentation with Sphinx", then the answer is "what's wrong with https://www.sphinx-doc.org? What do they lack?
I would like Sphinx's "engine" that
turns the input (consisting of reST
files) into HTML/CSS/JS to be
accessible from anywhere to make me
(and possible other contributors)
independent from a specific
workstation.
Sphinx is like a compiler. Everyone has their own copy on their workstation. They download the document source, make changes, commit the source changes, and upload the resulting document.
serve the generated documentation from
the same place.
Correct. After you download the source, make changes, regenerate the document and commit the changes, you upload the resulting document so it will be served from one -- and only one -- place.
Sphinx is a compiler. It is not a "web engine". It's a simple compiler that simply compiles your documentation into HTML so it can be served.
Interesting project! The main issue you're going to run into is that of filesystem access: The filesystem on App Engine is read-only, and based on looking at the source, Sphinx is fairly hard-coded to use the filesystem for output. It also expects to read the configuration file and input files from the local filesystem, which would make building docs for anything other than projects bundled with the app tricky.
It is possible to work around this, but it would require writing a simple virtual filesystem that uses the App Engine datastore, and using monkeypatching to make it work with the regular Python file interface. That's rather advanced for a "new to Python" project!
One other thing you might want to consider if you were pondering allowing users to upload projects to be documented: The Sphinx configuration file is in Python, so executing it could be dangerous - a user could do nasty things to your app with a malicious configuration file!
The difference between deployment locally via dev_appserver and remotely via appcfg has been - in my experience - limited to which of the two commands I execute. That said, I've no experience with Sphinx.
Sphinx compiles documentation, running it on a webserver makes as much sense as running gcc on a webserver.