Happy New Year 2015!
Feliz Año Nuevo!
Buon anno!
Felice anno nuovo!
Bonne Année!
Feliz Ano Novo!
Frohes Neues Jahr!
#HappyNewYear2015 pic.twitter.com/T3BCv7784X
— Uobis (@Uobis) December 31, 2014
From Everyone in Uobis!
Feliz Año Nuevo!
Buon anno!
Felice anno nuovo!
Bonne Année!
Feliz Ano Novo!
Frohes Neues Jahr!
#HappyNewYear2015 pic.twitter.com/T3BCv7784X
— Uobis (@Uobis) December 31, 2014
From Everyone in Uobis!
I wanted to clean up some Bootstrap files from a project directory. After the cleanup. I pushed the changes to the remote repo (BitBucket).
However, I noticed that the files that should be deleted (and was deleted on local repo), was still existing on the remote repo.
After some head scratching, i released that the problem was that I used the file system delete, instead of the git delete.
$ git rm $ git add . $ git commit -m "changes" $ git push
Everything was fine now and good, until I come back to see that i deleted an important directory due to a misuse of the “*” during the delete.
Well, that what and DSCM was meant for.. Git come to the rescue…. except that it took me 30mins or trying different command ( and help from Stackoverflow) to find the right combo, thus:
cf361cb is the last commit with the missing directory
$ git revert --no-commit cf361cb..HEAD $ git commit
This is a safe and easy way to rollback to a previous state. Checks for the missing directory
$ ls -ltr $ cd static/
Cleanup files
$ git rm *.css $ git rm *.js
Then commit and push
$ git add . $ git status $ 1398 git commit -m "UI file cleanup" $ git push
And Wossah!!
The git throws up a new error, “fatal: You are not currently on a branch”
I checked on the git
$ git status
And trully, you are not a branch!
I was getting loosing the modification twice after using 2 different command, until i hit on the right combo (also good help from stackoverflow)
$ git checkout -b newbranch $ git checkout master $ git merge newbranch $ git branch -d newbranch $ git status $ git push
Hurray!!
We have been trying to setup a default development environment.
We been trying different set up
I have been trying to make my default environment for development to be
C:\User\<username>\Env
(or other %VIRTUALENV_HOME%
location) and use virtualenv
to start a new environment. Doing this allows virtualenvwrapper-win
‘s workon
command to work.With Python becoming “the new Java” (aka reliable Blub), Cython is how you make it go fast 🙂 http://t.co/YwoqAVyxjF http://t.co/Fj966D2Z7A
— Balaji S. Srinivasan (@balajis) August 10, 2014
Step 3: Upload your Flask project using Git
Upload the project/ folder to the application directory using Git. “myapp” directory is created
git clone https://username@bitbucket.org/uobis0/myapp.git
All following instructions will assume you’re still in this directory.
virtualenv venv --python=python2.7
$ . venv/bin/activate $ easy_install-2.7 flask # Installs flask package for the app $ pip install -r /myapp/app/requirements.txt # Installs the packages for the app $ deactivate
Now, my ~/webapps/myapp directory list looks like the following:
drwxr-xr-x 7 uobis uobis 4096 Nov 11 14:29 apache2/ drwxrwxr-x 5 uobis uobis 4096 Nov 11 14:40 venv/ drwxrwxr-x 6 uobis uobis 4096 Nov 14 16:46 myapp/ drwxr-xr-x 2 uobis uobis 4096 Nov 11 14:29 htdocs/ -rw-rw-r-- 1 uobis uobis 292 Nov 18 15:14 wsgi.py
Step 4: Edit apache2/conf/httpd.conf
Using your favorite command line editor, open up the apache2/conf/httpd.conf file:
vim ~/webapps/myapp/apache2/conf/httpd.conf
Load Alias module (optional)
You’ll see a section where Apache Modules are being loaded. I had to manually add the Alias module to the bottom of the list (shown below).
. . LoadModule wsgi_module modules/mod_wsgi.so LoadModule alias_module modules/mod_alias.so #Your version of mod_wsgi might not need to add this.
Modify Alias and <Directory>
Add the following parameters to your <Directory> section:
WSGIScriptAlias / /home/username/webapps/myapp/wsgi.py <Directory /home/username/webapps/myapp/htdocs> AddHandler wsgi-script .py RewriteEngine on RewriteBase / WSGIScriptReloading On </Directory>
Now for the final edit of the config file.
Step 5: Make sure your main file is right
Ensure that, if your structure is package, your project’s __init__.py file is launching your Flask application. This is what the file at ~/webapps/myapp/app/__init__.py should look like:
from flask import Flask # Setting up the App app = Flask(__name__) app.config.from_object('config') # Importing the views for the rest of our site from app import views if __name__ == '__main__': app.run()
If you are using modules, the files should contain the app instantiation
app = Flask(__name__)
This will work nicely with our wsgi.py file, which we’ll set up next.
Step 6: Modify the htdocs/wsgi.py file
WebFaction should have created this file. In it are a few scripts, but you can completely remove those. Here is what the ~/webapps/myapp/wsgi.py file should contain:
import sys # Active your Virtual Environment, which I'm assuming you've already setup activate_this='/home/username/webapps/myapp/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) # Appending our Flask project files sys.path.append('/home/username/webapps/myapp/myapp') # Launching our app from main import app as application
Step 7: Restart Apache
The last step will be to restart apache, like so:
~/webapps/myapp/apache2/bin/restart
If you’re having trouble, take a look at your logs in the ~/logs/users/ directory.
The steps above makes updates very easy:
cd ~/webapps/myapp/myapp
git pull https://username@bitbucket.org/accout/myapp.git
~/webapps/myapp/apache2/bin/restart
Deploying Flask seems a lonely taks, becuase of dearth of articles or blogs that explain in. This is even worse when deploying on a shared server.
Most people seems to treat a python deployment as a django deployment. Since, there are cheap and available Flask hsting site, i went with Django host, but confirmed that we can host any other framework.
The good thing is that, there too many similarities, and most packages are already installed on the host.
1. Open putty and log into the hosts server (s17.wservices.ch)
2. Check that the following following packages are installed
python and python-devel: the Python interpreter and its development package
lighttpd: The Lighty web server and its development package
install postgresql postgresql-contrib: The PostgreSQL database server and its development package
git: source code version control system (we will use it to download and update the application)
gcc: the C/C++ compiler (needed to compile Python extensions)
sudo: a tool that helps users run commands as other users.
If not, install them.
sudo apt-get python python-devel lighttpd httpd-devel mysql-server mysql-devel git gcc
3. Configure passwordless login (if needed)
4. Create a directory for the application, and install the application from BitBucket
mkdir app
cd app
git clone git://bitbucket.org/peppe/peppe-ng.git
5. Check User permissions
chmod -R 777 *
6. Setup the database
Go to https://panel.djangoeurope.com/databases/
Login with a username and password, and then create a database and dump the content of the dev db
pg_dump peppedb > ppdbdump.sql
Transfer the file to live host
sftp outfile.sql peppe@s17.wservices.ch
Load the Db on the live host
psql peppedb < ppdbdump.sql
7. Setup the webserver
Paste at the end of this file ~/lighttpd/lighttpd.conf
#Peppe.com
$HTTP[“host”] =~ “(^|.)peppe.com.ng$” {
fastcgi.server = (
“/flask.fcgi” => (
“main” => (
“socket” => env.HOME + “/mysite_project/mysite.sock”,
“check-local” => “disable”,
)
),
)
alias.url = (
“/media” => env.HOME + “/mysite_project/media”,
)
url.rewrite-once = (
“^(/media.*)$” => “$1”,
“^/favicon.ico$” => “/media/favicon.ico”,
“^(/.*)$” => “/flask.fcgi$1”,
)
}
Replace mydomain.com with the name of your domain. Be sure to escape all dots of your website’s name (put a backslash before it: .). Replace your_django_project/media with the path of you media directory (relative to your home directory). Replace mysite_project/mysite.sock with the path to your fastcgi socket file
Now you can launch your lighttpd:
~/init/lighttpd start
Whenever you make changes to the configuration, you can reload the configuration or restart lighttpd:
~/init/lighttpd reload
~/init/lighttpd restart
9. Configure the db and start
10. Install application updates
Create a folder for storing Virtualenv environments
C:Usersamachefe>mkdir env
C:Usersamachefe>cd env
Create a virtual environment VCMS by running the virtualenv command.
C:>powershell
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:>
PS C:Usersamachefeenv>virtualenv vcms
New python executable in vcmsScriptspython.exe
Installing setuptools…………….done.
Installing pip……………….done.
In Microsoft Windows, before activating the virtual environment, ensure that the new environment is used by setting the Powershell execution policy
PS C:> Set-ExecutionPolicy RemoteSigned
PS C:> exit
Activate the virtualenv environment just created
PS C:Usersamachefeenv>vcmsScriptsactivate
(vcms) C:Usersamachefeenv>
(vcms) C:Usersamachefeenv>pip list
(vcms) C:Usersamachefeenv>pip show
ERROR: Please provide a package name or names.
(vcms) C:Usersamachefeenv>pip install django
Downloading/unpacking django
Downloading Django-1.5.1.tar.gz (8.0MB): 8.0MB downloaded
Running setup.py egg_info for package django
warning: no previously-included files matching ‘__pycache__’ found under directory ‘*’
warning: no previously-included files matching ‘*.py[co]’ found under directory ‘*’
Installing collected packages: django
Running setup.py install for django
warning: no previously-included files matching ‘__pycache__’ found under directory ‘*’
warning: no previously-included files matching ‘*.py[co]’ found under directory ‘*’
Successfully installed django
Cleaning up…
Storing complete log in C:Usersamachefepippip.log
(vcms) C:Usersamachefeenv>pip list
Django (1.5.1)
(vcms) C:Usersamachefeenv>
Deactivate after installing
(vcms) C:Usersamachefeenv>deactivate
C:Usersamachefeenv>
Setting up Aptana Studio
One of the best (and free) IDEs for is Aptana Studio. Aptana Studio is a complete environment that includes extensive capabilities to build Ruby and Rails, PHP, and Python applications, along with complete HTML, CSS and JavaScript editing. Aptana is based on Eclipse, and has one of the best python plugin, PyDev.
It has gives you two options for download. You can either install Aptana on top of your pre-existing Eclipse installation (Eclipse Plug-in Version), or install a standalone version of Eclipse with Aptana pre-configured. I prefer the stand alone version
To create a new Django project in Aptana, go to File->New -> Other. Select the PyDev folder, and finally, the PyDev Django Project option, and click next. Give the project a name.
Under the Interpreter, click to configure a new interpreter.
Hit New… Add Name for the interpreter, and specify a path to your newly made virtualenv. Click Ok
manually select the C:Python27Lib folder. Click OK
Click OK, to close the Python interpreter selector and return to the New Project box.
Select the Interpreter you just created in the last step, and Click Next. Complete the Requirement to create a project.
To test the project, Click the Aptana Studio RUN bottom
Aptana Studio Run button |
Check if the project was successful from the browser
NB: You can also add a new Python Interpreter from Preferences > PyDev > Interpreter – Python settings.
The recommended way to install Django is with pip. pip is a tool for installing and managing Python packages.
Before installing Django, you need to install pip!
1. Install python
First things first – get Python! You can get the Python 2.7.3 (the current Python 2.x version as of this writing) 32-bit installer from http://python.org/download/.
C:>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
Type quit() to close the python interpreter
>>>
>>> quit()
NB: Before punning the command, remember to add the python on the windows environment PATH
2. Install Distribute. Distribute is a pre-requisite for pip
Download the distribute_setup.py file to you computer. Click on the file to install Distribute, or run from the command prompt.
C:>python distribute_setup.py
Extracting in c:usersamache~1appdatalocaltemptmpbjtb6b
Now working in c:usersamache~1appdatalocaltemptmpbjtb6bdistribute-0.6.36
Installing Distribute
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at c:python27libsite-packages
Non-egg installation
Moving elements out of the way…
Already patched.
..
Installed c:python27libsite-packagesdistribute-0.6.36-py2.7.egg
Processing dependencies for distribute==0.6.36
Finished processing dependencies for distribute==0.6.36
After install bootstrap.
C:Python27Libsite-packagessetuptools-0.6c11-py2.7.egg-info already exists
3. Install pip
Now, Download the pip install script from GitHub.
Install by clicking the script or running from python command prompt
C:>python get-pip.py
Downloading/unpacking pip
Downloading pip-1.3.1.tar.gz (247Kb): 247Kb downloaded
Running setup.py egg_info for package pip
warning: no files found matching ‘*.html’ under directory ‘docs’
warning: no previously-included files matching ‘*.txt’ found under directory
‘docs_build’
no previously-included directories found matching ‘docs_build_sources’
Installing collected packages: pip
Running setup.py install for pip
warning: no files found matching ‘*.html’ under directory ‘docs’
warning: no previously-included files matching ‘*.txt’ found under directory
‘docs_build’
no previously-included directories found matching ‘docs_build_sources’
Installing pip-script.py script to C:Python27Scripts
Installing pip.exe script to C:Python27Scripts
Installing pip-2.7-script.py script to C:Python27Scripts
Installing pip-2.7.exe script to C:Python27Scripts
Successfully installed pip
Cleaning up…
Test the installation
C:>pip
Usage:
pip <command> [options]
4. Install virtualenv (Not Compulsory, but very advised)
C:>pip install virtualenv
Install virtualenvwrapper (for microsoft Windows)
C:>pip install virtualenvwrapper-win
And you are good to go!!
Thanks to tyler butler for his informative procedure