Code Monkey home page Code Monkey logo

drapache's Introduction

Drapache

apache for your dropbox

About

A python server that uses the dropbox API to serve files that are hosted on dropbox. It will not be particularly useful to a developer who is comfortable with git, heroku, ftp, or another method of hosting a website. It will be useful, however, to people who don't know how to use these tools. It's very simple - whatever is in the Drapache folder in the users dropbox /Apps folder will be immediately available on the internet. Get it set up at get.drapache.com

.dbpy

Besides being able to serve static files, Drapache also implements a rudimentary CGI/PHP-like framework in python. Files that have the extension .dbpy or start with the string "#DBPYEXECUTE" will be treated as "dropbox python" files and executed by the Drapache server, returning anything that is printed to standard out to the clients browser.

Although far from finished, the dbpy framework is enough for beginning programmers to get started building dynamic websites. Check out blog.drapache (on github too) for a blogging system I scraped together that runs on drapache and demonstrates what can be done with dbpy.

Misc. Features

It will create an index for a folder if one doesn't exist, using a template found in Drapache/_templates/. Files or folders that begin with '_' will not be served, returning instead a 403-Forbidden HTTP response. Right now they do show up in an auto-generated index, but that is for debugging purposes and could be easily changed

Technical

Working on documenting both the server as well as the dbpy framework.

This is the high level life-cycle of a request:

  1. A frontend handles the http request, and creates a Request object. It handles parsing the Host header for the requested subdomain, parsing GET/POST parameters, looking up any dropbox oauth for the requested subdomain, and creating a dropbox API client. The frontend passes the request and client off to a DropboxServer.
  2. The DropboxServer parses the path, and looks up the metainfo for the file requested. If it is a directory, it goes through some logic to create and index page. If it is a file, it downloads it. If it is a static file, it passes it back to the frontend, which writes it to the internet. If it is a dbpy file, it passes it, along the request and client, to dbpy.execute.
  3. dbpy.execute creates a sandbox using the pysandbox module by haypo. It creates a number of objects necessary to execute a dbpy file, gets a dictionary of the dbpy built-in functions, and creates a new thread in which to run the downloaded dbpy script. It creates a new, in memory, stdout, and starts the created thread.
  4. This thread activates the sandbox, and calls exec on the downloaded script, capturing any errors. The running script has access to the request, response, sessions, templates, and the dropbox file system through the dbpy framework. This thread will be killed by the caller after a certain amount of time (right now 25 seconds) and an exception will be raised. Errors in this thread are caught and passed back to the caller.
  5. Once the thread either finishes or is killed, any clean-up from the dbpy script takes place, the fake stdout is replaced with the real stdout, and the error output or actual output of the dbpy script is passed back to the DropboxServer with any headers and status code of the new Response.
  6. The DropboxServer passes this response back to the frontend, which writes it to the internet.

Running an instance locally

  1. make sure that all the requirements present in requirements.txt are satisfied (pip install -r requirements.txt will do it, as should starting a new virtualenv I think)
  2. Go to dropbox.com/developers and create a new app
  3. Fill in the file config.py with the app key and secret of that new app
  4. run python get_dropbox_oauth.py [TESTING_SUBDOMAIN] >> [SUBDOMAIN_FILE] (where TESTING_SUBDOMAIN is the subdomain you want to add to your local instance, and SUBDOMAIN_FILE is the name of the file in which you want to save subdomains)
  5. In config.py, fill in the SUBDOMAIN_FILE variable with the file path from step 3.
  6. Add a line like '127.0.0.1 TESTING_SUBDOMAIN.localhost' to your /etc/hosts file (this enables local subdomain routing.. if there is a better way let me know!)
  7. Run python server.py and you should have a drapache instance on localhost (the default port is 5501)

Notes:

  • add more testing subdomains by repeating step 4 for other subdomains
  • There are other ways of managing subdomains than a flat file.. look in subdomain_manager.py for the base class and an implementation of managing subdomains with mysql
  • This will create a folder in your dropbox /Apps folder with the name of whatever app you created in step 2, and your local instance will serve from that folder, not the Drapache folder that you will get if you sign up through get.drapache

Testing

The tests test the functionality of the dbpy framework, which is sufficient for integration testing of the whole system. To use, create a symlink from the folder dbpy_test to wherever you are serving drapache file from, then go to test.html in that folder. It uses the QUnit testing framework.

drapache's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

drapache's Issues

Can't repeat installation

So I went to try drapache and I've chose random domain just to give it a try. Everything worked great and after that I've try to register another domain - didn't work. I've tried to manually delete all files, apps inside "my apps", everything that has something to do with Drapache and every time was the same. When I've tried to register new domain, it pointed out that I already have another domain registered (and my Apps/Drapache folder was recreated - but just with one dropbox file inside).

Any solution for that? Thanks.

Domain issue?

Hi. Looks like your domain name, http://drapache.com/ is down.
Today we can read this message: NOTICE: This domain name expired on 03/11/2013 and is pending renewal or deletion.

Support some sort of URL rewriting in Drapache

A simple URL rewriting mechanism would be very very welcomed. The good news is it's perfectly safe to add URL rewriting to Drapache and I will surely enable certain kinds of apps and scripts to be much more easily written this way.

Something with all of the power of mod_rewrite in Apache would be cool but I guess we don't need it since we got Python, right?

How about redirecting all 404s to a top level _rewrite.dbpy script if it's present?

Once you have that you would only need to provide us with a way to read the original requested path and we can put together our own pattern matching and URL rewriting mechanism.

Here's some code sample to help illustrate the idea:

import re

request = dbpy.http.get_request()

m = re.compile('^/posts/(?P<post_id>\d+)$')

if m.matches(request.redirect_uri):
post_id = m.groupdict()['post_id']
dbpy.http.redirect('/read_post.dbpy?post_id=%d' % post_id)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.