Docker python hello world project

Categories: LinuxPython; Tagged with: ; @ January 26th, 2016 23:12

create a Dockerfile 
this image will install python and start a SimpleHTTPServer:

FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
CMD ["bash"]

RUN apt-get update
RUN apt-get install -y python

CMD python -m SimpleHTTPServer 8000

Build project
docker build -t myapp:latest .
run docker image
docker run -P myapp
-P for port forwarding:  Publish all exposed ports to random ports
check the web page
find port by:
docker ps -l

This project can be found here:

One line to share the current folder via HTTP

Categories: Python; Tagged with: ; @ November 7th, 2015 18:23
>python -m SimpleHTTPServer $PORT

Dropbox Python SDK 2.2.0 bug: commit_chunked_upload ?

Categories: Development NotesPython; Tagged with: ; @ August 2nd, 2015 23:04

Issue:  dropbox keep ignoring the first folder when committing a chunked upload:

After chunked uploading completed, commit the file by:

response = self.dropbox_client.commit_chunked_upload('/backup/', upload_id, False)
remote_path = response['path']

My understanding was remote_path in the response should be same as the full_path I passed: ‘/backup/’, however, the remote_path is: ‘’. form /commit_chunked_upload:

The full path to which the chunks are uploaded, *including the file name*.
If the destination folder does not yet exist, it will be created.

full path with filename, and it’ll be used by:

url, params, headers = self.request("/commit_chunked_upload/%s" % full_path,
                                    params, content_server=True)

a http request to : /commit_chunked_upload//backup/ will be sent. however, the actual server url is:<path>

Solution / workaround

1. fix the SDK :
Following CheckedUpload class,  the commit url can be generated by:

path = “/commit_chunked_upload/%s%s” % (self.client.session.root, format_path(path))

2. add ‘auto’ in the front of the remote path:

response = self.dropbox_client.commit_chunked_upload('auto/' + remote_path, upload_id, False)

PyQt ProgressBar: Update progress from other threads

Categories: Python; Tagged with: ; @ May 14th, 2015 23:40

Issue 1: UI is no responding when the progress is running

Create new thread to perform the progress:

Issue 2: QThread: Destroyed while thread is still running

Try to keep a reference:

Issue 3: QWidget::repaint: Recursive repaint detected

Use single to update progress:


Example: UploadThread:

class UploadTaskQtThread(QtCore.QThread):
    tick = QtCore.pyqtSignal(int, name="upload_changed")

    def __init__(self, client, local_path, remote_path):
        self.client = client
        self.local_path = local_path
        self.remote_path = remote_path
    def on_progress(self, progress):
        self.tick.emit(progress * 100)
    def run(self):
        self.client.upload_file(self.local_path, self.remote_path, self.on_progress)


    def upload(self, local_file_path, remote_path):
        self.upload_thread = UploadTaskQtThread(client, local_file_path, remote_path)

My first Python Class

Categories: Python; Tagged with: ; @ May 14th, 2014 23:24

User class, has one attribute ‘name’:
class User(object):
        def __init__(self, name):

        def sayHi(self):
                print, " say hi to you"

        def hello(self, *friends):
                f1, f2 = friends
                print "hello my friends: ", f1", and ", f2

Initialize User instance and call the methods:

>>> import User
>>> john = User.User("John")
>>> john.sayHi()
John  say hi to you
>>> john.hello("Luna", "Peter")
hello my friends:  Luna  and  Peter

I got confused, because I come from Java, why every method need a ‘self’? we use the instance invoke the method,  why we need to supply the instance itself?

Maybe they are static?  let’s try to invoke the method in ‘Static’ way:

>>> User.User.sayHi()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unbound method sayHi() must be called with User instance as first argument (got nothing instead)

Ok, how about this:

>>> User.User.sayHi(john)
John  say hi to you

It seems these instance method can be invoked both by Class and instance… that’s why  every method requires a ‘self’?

Ok, let’s add a static method:

        def staticHi():
                print "Static Hi"

Invoke it:

>>> User.User.staticHi()
Static Hi
>>> john.staticHi()
Static Hi

Static method can be called both by Class  and instance.


Some topic about ‘slef’:

Newer Posts <-> Older Posts

// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.