1. New to the forums? Check out our Mentorship Program!
    Our mentors will answer your questions and help you become a part of the community!
  2. Welcome to Smogon Forums! Please take a minute to read the rules.

Smogon Programming Megathread

Discussion in 'Site Projects' started by chaos, Jul 6, 2007.

  1. chaos

    chaos
    is a member of the Site Staffis a Battle Server Administratoris a Programmeris a Smogon IRC SOPis a Contributor to Smogonis an Administratoris a Tournament Director Alumnusis a Researcher Alumnus
    Owner

    Joined:
    Dec 18, 2004
    Messages:
    9,631
    A work in progress. It's 4:34 AM. Please don't post in this thread if you aren't a programmer for this site. :cloud:

    Python

    The whole of Smogon's website is in Python. If you don't have python already, you... might want to get it at www.python.org. It should come with setuptools, but if it doesn't or if the setuptools it comes with is outdated please download setuptools at http://cheeseshop.python.org/pypi/setuptools . Unzip, and type python setup.py install

    Get all the libraries that Smogon uses.

    easy_install Colubrid
    easy_install flup
    easy_install Mako
    easy_install SQLAlchemy
    easy_install PIL


    and for your own benefit

    easy_install ipython
    easy_install pyreadline


    If you want to do local testing of the applications, you'll need to get MySQL at www.mysql.com. I'm not going to go through how to install it, at least not now. Contact me for a database dump of whatever application you are working on.

    easy_install MySQL-python

    You'll probably want a good IDE, so download http://mmm-experts.com/Downloads.aspx?ProductId=4 PyScripter. It kicks fucking ass, and it has shell integration so you can use SVN with it. (windows only)

    Docs:
    Python tutorial: http://docs.python.org/tut/tut.html
    Python Standard Library: http://docs.python.org/lib/lib.html
    SQLAlchemy http://www.sqlalchemy.org/docs/
    Colubrid http://wsgiarea.pocoo.org/colubrid/documentation/
    Mako http://www.makotemplates.org/docs/

    Subversion

    Windows user: http://tortoisesvn.net/downloads
    Linux user: you should know how to use svn

    Contact me for a password!

    How to use tortoisesvn: http://www.mind.ilstu.edu/research/robots/iris4/developers/svntutorial/

    Import svn://smogon.com/smogon

    Structure of a Smogon application

    coming later


  2. chaos

    chaos
    is a member of the Site Staffis a Battle Server Administratoris a Programmeris a Smogon IRC SOPis a Contributor to Smogonis an Administratoris a Tournament Director Alumnusis a Researcher Alumnus
    Owner

    Joined:
    Dec 18, 2004
    Messages:
    9,631
    Also Brain, I was right. it was the "tcp6" thing that was fucking up subversion, it took me forever to find any documentation about getting it to use ipv4
  3. Surgo

    Surgo goes to eleven
    is a Site Staff Alumnusis a Smogon IRC AOp Alumnusis a Programmer Alumnusis a Contributor Alumnusis an Administrator Alumnus

    Joined:
    Jul 10, 2006
    Messages:
    3,635
    Eclipse

    Eclipse is an IDE created by guys from IBM, some other companies, and random people on the internet for the past few years. It seems to be pretty good, and will work well if you aren't using Windows and can't use Pyscripter; I just got it up and running, and here's how you can do it too!

    * Step 1: Download Eclipse
    Windows
    Mac
    Linux

    These are binary files; I compiled my version from scratch on Linux. If you want to do that you'll find the download somewhere on the site (they make it fucking impossible to find, took me forever and now I forgot) and the Ant build tool from Apache along with a bunch of libraries.

    * Step 2: Run Eclipse

    Run the executable file "Eclipse" that comes with the download. If this doesn't work for you like it didn't for me because fucking Java on Linux is still completely moronic, you'll need to run the launcher manually. Windows users can probably just double-click on the jar file to get it to execute, it's named something like "org.eclipse.equinox.launcher_1.0.0.v20070606.jar" in the plugins directory. Fucking useless Java.

    * Step 3: Update Eclipse
    You'll want to install PyDev (for developing Python), PyDev Extensions (extension for PyDev...why don't they put them in the same package? The world will never know), and Subclipse (automatic integration of Subversion and Eclipse). One thing Eclipse does really well is that it has an awesome update manager, though they put it in a rather odd place.

    After launching Eclipse and making a workstation directory, go to Help->Software Updates->Find and Install. Click on the radio button that says "Search for new features to install" and click Next. Click on "New Remote Site" and add the following websites:

    name: PyDev
    site: http://pydev.sourceforge.net/updates/

    name: PyDev Extensions
    site: http://www.fabioz.com/pydev/updates

    name: Subclipse
    site: http://subclipse.tigris.org/update_1.2.x

    Click finish, and it will contact everything that's checkmarked and get information as to what's there. Now when the Updates screen comes back up it will give you a list of choices you can click on. Get PyDev, the PyDev extensions (none of the Mylar stuff, whatever the fuck that is), and Subclipse (none of the optional integrations, whatever the fuck they are). Also feel free to download whatever feels appropriate from Europa etc...I haven't checked any of it out.

    Now click finish, it will download, accept the licenses, it will install, and restart Eclipse. Go back to Help->Software Updates, "Search for new features to install", and then remove the custom sites you entered because for some moronic reason installing the plugins added their sites to the update list a second time, despite you already having them there.

    Okay, that's installing Eclipse. Coming soon, using it...
  4. chaos

    chaos
    is a member of the Site Staffis a Battle Server Administratoris a Programmeris a Smogon IRC SOPis a Contributor to Smogonis an Administratoris a Tournament Director Alumnusis a Researcher Alumnus
    Owner

    Joined:
    Dec 18, 2004
    Messages:
    9,631
    Todo: talk about formencode, jquery, autocomplete, form validation
  5. Articuno64

    Articuno64 1 to 63 were taken
    is a Tournament Director Alumnusis a Site Staff Alumnusis a Battle Server Admin Alumnusis a Programmer Alumnusis a Smogon IRC SOp Alumnusis an Administrator Alumnus

    Joined:
    Dec 18, 2004
    Messages:
    2,461
    not related to the site per se, but I'll be back on board to work on Competitor (with XUL) in about 5 weeks.
  6. chaos

    chaos
    is a member of the Site Staffis a Battle Server Administratoris a Programmeris a Smogon IRC SOPis a Contributor to Smogonis an Administratoris a Tournament Director Alumnusis a Researcher Alumnus
    Owner

    Joined:
    Dec 18, 2004
    Messages:
    9,631
    (Part 1 to come eventually :( I really dont want to write that)
    The Smogon API Part 2: Handling logins

    As I have said at random times in #insidescoop, the new Smogon site has a very
    comprehensive API to make programming as absolutely painless as possible. The
    first of a long series of documents detailing this API is contained... within this post!
    I'll try to do a new one every once in a while, as eventually when I'm done I'd like it
    if other programmers helped me without the site :-) This documentation is available
    via Python help system as well, but I figure it'd be even better to provide a
    bonafide tutorial on this shit.

    ** The user database currently comes from vBulletin. While this API may change slightly
    in '08 when I write our own forum system that integrates with the whole of the site,
    the function names and fundamental concepts within shouldn't change. For the most part,
    this is a finalized API. At least... I hope. No guarantees!***

    A quick, and dirty example to start things off!

    Code:
    from smogon.helpers.user import cond_login
    
    def index(req):
        login = cond_login(req)
        print login.user_username
    
    A surprising amount of functionality for 4 lines of code! What this sample does
    is print the logged in user's username. For the more attentive, you may be wondering...
    "what if they aren't logged in?" "what if they are banned?" and other questions.
    That's the beauty of the login API; it ALWAYS returns a valid login object. If the user
    can't login for whatever reason then an exception is raised and we never reach the
    print statement. Pretty awesome huh? The defaults for helpers.user.cond_login take
    the user to a login page that redirects to the current page if a session can't be found.

    Customizing cases!

    Sometimes you don't want the default functionality every single time. What if you don't give a
    crap about whether they can login or not? Try the uncond_login function. uncond_login, despite the name,
    CAN raise exceptions, they are just of a different nature. It returns None if the user can't login
    but has the ability to raise exceptions if a user is banned, for instance.

    Code:
        login = uncond_login(req)
        print login
    
    This function is useful for, say, when you never really use the login object but just want
    to pass the information to a template so it can say who is currently logged in.

    It's possible to give custom logic to both cond_login and uncond_login. Let's take a look
    at their function signatures first though:

    Code:
    def uncond_login(req, **kwargs)
    def cond_login(req, **kwargs)
    
    req is an instance of the colubrid Request object. It's passed as the first parameter
    to every HTTP request function, so just blindly pass it on.

    Each function can also take a series of keyword arguments. These arguments are functions
    that return exceptions. Any keyword argument that is left out resorts to the defaults
    for that function. You can pass True if you want the function to raise a default exception.

    Some examples:

    Code:
    from colubrid.exceptions import HttpFound, BadRequest
    from smogon.helpers.user import cond_login, uncond_login, NotLoggedIn, Banned
    
    # Redirect all banned users to banned.html, print login object of logged in and unlogged in users.
    def example1(req):
        login = uncond_login(req, banned=lambda req, login: HttpFound("/banned.html"))
        print login
    
    # Hmm... redirect users to a login screen if they aren't logged in, but print a banned msg if they are banned.  
    def example2(req):
        try:
            login = cond_login(req, banned=True)
            print "Welcome to the club, non banned user."
        except Banned, e:
            print e.message
    
    # Make sure the user knows that he is new. 
    def example3(req):
        try:
            login = cond_login(req, not_logged_in=True)
            print "Hey buddy :D"
        except NotLoggedIn, e:
            print "WHATS UP YOU'RE NEW, GO LOGIN $_$"
    
    The main reason for passing True to these arguments is when you want to render a different
    template depending on a condition, since you can't raise that as an exception.
    Other logic should be handled via functions that return colubrid exceptions.

    Reference coming soon.
  7. Articuno64

    Articuno64 1 to 63 were taken
    is a Tournament Director Alumnusis a Site Staff Alumnusis a Battle Server Admin Alumnusis a Programmer Alumnusis a Smogon IRC SOp Alumnusis an Administrator Alumnus

    Joined:
    Dec 18, 2004
    Messages:
    2,461
    I've been without internet for a couple weeks since I moved to a new place, but now it's back. Work on the Competitor client will resume. Where I left off a couple weeks ago, I had some very exciting stuff going.

Users Viewing Thread (Users: 0, Guests: 0)