CyberKeeda In Social Media
Showing posts with label GITHUB. Show all posts
Showing posts with label GITHUB. Show all posts

How to make your Python Django App Reusable


Django is cool and it's features like any other python libraries and frameworks are way more cooler then it.

One of the best feature is to make your django app easily distributable for re usability.

Within this blog post, we will cover.
  • How can we build a django app a python package as xyz.tar.gz
  • How can be uploaded our created django app python package to Python Package Index, simple know as PyPI.
  • How we can Install our created package locally via tar.gz file.
  • How can we install using standard pip command as "pip install your_py_package"
Assumptions.
  • We assume you already have a running Django Project and beneath it there must be an application, which you want to package and make it disributable.
  • Here in this blog post we already have a Django project named as docdocGo and within it we have created a django application named as FilesNow, we will cover all things taking it an example.
  • FilesNow is an django application, that can be used to download contents from a AWS S3 bucket within it's temporary directory and serve it as a presentable media to view or download for a user, it deletes the files after a fix set interval. 
  • FilesNow on GitHub linkhttps://github.com/Jackuna/django-filesnow
Here is how our django project and it's  directory look like.

Dependencies

  • Python 3+
  • Django 2.2+
  • PIP
  • Twine ( pip install twin )

Lets proceed and how to Package our filesnow django app.
  1. Create a new empty directory outside our django project and name it something relevant to your app, here we will use it name as django-filesnow.
  2. Copy the entire application directory and paste under newly created directory.
  3. Toggle to directory django-filesnow and lets move ahead and create few required files within it.
  • Create a file django-filesnow/README.rst with the below content and do replace with your own.
Content of django-filesnow/README.rst
=========
FilesNow
=========

FilesNow is a Django app to download documnets, images 
from AWS S3 and serve is a temporary static content to customers.

FilesNow is a way to serve AWS S3 documents/media files
without giving access to your s3 buckets.

FilesNow itself cleans it's downloaded presentable
files, as such maintainig a healthy file system

Dependecies
-----------
AWS Boto3 Framework : pip install boto3
Configure AWS Credentilas using command : aws configure

Quick start
-----------

1. Add "filesnow" to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        ...
        'filesnow',
    ]

2. Include the polls URLconf in your project urls.py like this::

    path('filesnow/', include('filesnow.urls'))

 
3. Start the development server ``python manage.py runserver 0.0.0.0:9090``

4. Visit http://127.0.0.1:9090/filesnow and explore it.
  • Create a license file django-filesnow/LICENSE , choose license as per requirement of yours ( GNU, BSD, MIT ) etc, Choose a license website ( https://choosealicense.com/ ) can help you to guide about your required license and it's content. I have used MIT license and you can find it's content within my Github repo.
  • Create two setup files within same directory and name it as django-filesnow/setup.cfg   and django-filesnow/setup.py with the below content and do replace with your own.
Content of django-filesnow/setup.cfg
[metadata]
name = django-filesnow
version = 0.1
description = A Django app to download cloud contents.
long_description = file: README.rst
url = https://github.com/Jackuna/django-filesnow
author = Jackuna
author_email = admin@cyberkeeda.com
license = MIT License
classifiers =
    Environment :: Web Environment
    Framework :: Django
 Framework :: Django :: 2.2
    Intended Audience :: Developers
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent
    Programming Language :: Python
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3 :: Only
    Programming Language :: Python :: 3.6
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Topic :: Internet :: WWW/HTTP
    Topic :: Internet :: WWW/HTTP :: Dynamic Content

[options]
include_package_data = true
packages = find:
Content of django-filesnow/setup.py
from setuptools import setup

setup()
  • Only Python modules and packages are included in the package by default. To include additional files, we’ll need to create a MANIFEST.in file.  To include the templates, the README.rst and our LICENSE file, create a file django-polls/MANIFEST.in with the following contents:
Content of django-filesnow/MANIFEST.in
include LICENSE
include README.rst
recursive-include filesnow/static *
recursive-include filesnow/templates *
So now we are all done with creation of required files in order to package your app, lets toggle again into the parent directory ( django-filesnow )and open a terminal/command prompt and run the below command to build our package.
# python setup.py sdist
Once command ends with successfully, and additional directory with name "dist" will be created, it contains our bundled and packaged django app, in our case  django-filesnow-0.1.tar.gz has been created.

Thus we have packaged our django app by name django-filesnow-0.1.tar.gz, we can distribute it as per your requirement, like uploading to repositories like github, email, uploading to any forum or website.

Let's know how to install our packaged filesnow django app django-filesnow-0.1.tar.gz, use the below command to install it.
# python -m pip install --user django-polls-0.1.tar.gz
Within Above command will install it, for windows we can located the installed application by name "filesnow" under directory.

"C:\Users\Jackuna\AppData\Roaming\Python\Python37\site-packages\filesnow"

Please note:
Above highlighted in red may varry, depending upon your system and package.
Package will be installed by name filesnow only not django-filesnow.
Within next post, we will know the remaining topics !

Read more ...

How to SSH in git behind proxy on windows



SSH into GIT behind proxy.

Steps.

  • Open Git Bash on the repository folder.
  • Create a new ssh config file to store values  ~/.ssh/config

cybeerkeeda@Linux-Maniac:~ vim ~/.ssh/config
  • Copy paste the below lines within the file.

ProxyCommand connect.exe -H yourproxyip:proxyport %h %p 

     Host github.com 
     user git 
     port 22 
     Hostname github.com 
     IdentityFile "c:\users\cyberkeeda\.ssh\id_rsa" 
     TCPKeepAlive yes 
     IdentitiesOnly yes

  • Edit few lines out of it.
  1.           ProxyCommand connect.exe -H yourproxyip:proxyport %h %p 
  2.           IdentityFile "c:\users\cyberkeeda\.ssh\id_rsa" 
      Use your proxy ip/url and port 
      Use your Identity file.

Once configuration saved check again.
cybeerkeeda@Linux-Maniac:~ service sshd restart
If required, do export http_proxies into command lines too.

export http_proxy=http://yourproxyip:port/
export https_proxy=http://yourproxyip:port/
Read more ...

How to SSH and authenticate to github central repository



How to authenticate your computer to pull, push, fetch, commit to your central github account.
Steps:

  • Generate your SSH-Keys.
cybeerkeeda@Linux-Maniac:~ ssh-keygen
Provide the details that it's asking from you, these details are optional you can even hit enter every time.
Generating public/private rsa key pair.Enter file in which to save the key (/home/cyberkeeda/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/cyberkeeda/.ssh/id_rsa.Your public key has been saved in /home/cyberkeeda/.ssh/id_rsa.pub.The key fingerprint is:SHA256:j6S60jQqGdhgaikn7W37h4//fWIxfuuPn8/O8hxxeTBeS8 cyberkeeda@Linux-ManiacThe key's randomart image is:+---[RSA 2048]----+|              . .||               +o||               ++||  .   .       E =|| o o o .S      ..||o o = .o.o   o . || + + ...o.... * .||o o ..  .o. .=.*o|| . .o. ++ ...o*B%|+----[SHA256]-----+

So your key has been generated, now we will be using the public key  /home/cyberkeeda/.ssh/id_rsa.pub kto authenticate your computer.

  • Copy your key.

cybeerkeeda@Linux-Maniac:~ cat /home/cyberkeeda/.ssh/id_rsa.pub
 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxzpbwBvPJ3LHJQpfxff860P4jKISitz+MueO2DFih9y97vldDhC9Ih0Q6Enw6J0YA9Z9IN+aSR7oBhwVgJGmYp1MqoS7NRuJ+EBo6ggl4ff9SJJznZMAN1/5xXGgv8lMs0KxV14aCn0KZUej2gJnkACSEilYRjU4/Fxsf+PSRNgABkQ0aFM8XodFZtlX5oTdtkkF9A16DpCGslkdCDgWR0MCxs5nB+MOIEnTTRfIPqxq7JgieVblCdW7O+7Lo8ugb0/wwv6I1AXH5Nf6h38uO3tZuM0ipc338dkTO94iCAp8129EOBqH74+tOey54WjS7m8eAtOs2W+JpUMI873qp cyberkeeda@Linux-Maniac



  • Login to your github account.
  • Click on Settings from from the drop down menu.
     

  • Click on SSH and GPG Keys
  • Click on SSH Key in order to add your ssh key


  • Copy paste the public ssh-key that we have copied earlier
  • Add any title to identify your machine 


























So we are done with github part, now lets authenticate our computer to github.
Below command will help you to complete authentication.Note : It will ask for your github credentials, do provide it.
cybeerkeeda@Linux-Maniac:~ ssh -T git@github.com
A success welcome message will appear in case if everything went successful.





Read more ...
Designed By Jackuna