Wednesday, September 26, 2012

Use Fabric more!

I have been really busy these days. I have many things I want to write about. Oh please good nature let me have some free times to write about things!

Anyway. I just happened to be on StackOverflow. There were two questions on sending files remotely. One was copying over to another machine, and another through FTP.

I am against using raw connection. Fabric is designed for deployment, so I am a strong advocate of using it.

How to automate the sending of files over the network using python?
Python Script Uploading files via FTP

I wrote the scripts very quickly.

    #!/usr/bin/python
    from fabric.api import run, env, sudo, put

    env.user = 'username'
    env.host = ['hostname,]
    #env.password = 'my_lovely_password'

    def copy():
        put('wong_8066.zip', '/home1/yeukhon/wong_8066.zip')

    def copy2():
        put('wong_8066.zip', '/www/public/wong_8066.zip')


You can save it as fabfile.py and run it via by calling fab task_name  or multiple task names all together.

If you need to automated it you should specify the path to the ssh key. Hardcoding the password (for FTP, for example) is OK if this is a personal thing.

Seriously... use Fabric more. Sadly, GLASSLAB needs a better automation system so we have to go with Chef.

Friday, September 14, 2012

Mocking sucks! I hate mocking!

I use Mock very frequently in my unittests because I need to isolate my system under test. But I hate mocking because it always give me problems. The documentation gives made-up examples that are independent from other sections in the documentation.

Fine. I am fine with that, but why the hell do I need to use .return_value all the time in my mock object?

I am consistently biting myself with mock library and I have wasted more time on mocking my objects more than me watching a two-hour movie.

The number one thing I hate about mocking is when it returns a Mock object when I call it. Like what the fuck man? Seriously.

Here is the latest issue I have with mocking: [TIP] Mock returns a mock using autospec

If this was such an easy question people would have answer it a long time ago. Why none? Because it is so god damn hard I think!

If there was a different library to do mocking I'd go with that AS LONG AS IT IS SIMPLE TO MOCK.