File: md5sum.py

package info (click to toggle)
gnome-commander 1.2.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 13,604 kB
  • ctags: 5,652
  • sloc: cpp: 38,403; sh: 9,339; xml: 6,751; ansic: 2,984; lex: 616; makefile: 386; python: 42
file content (45 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#       md5sum python plugin
#       Copyright (C) 2007 Piotr Eljasiak
#
#    Part of
#       GNOME Commander - A GNOME based file manager
#       Copyright (C) 2001-2006 Marcus Bjurman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

try:
    import gnomevfs
except ImportError:
    import gnome.vfs as gnomevfs

import os
import string
import md5


def main(main_wnd_xid, active_cwd, inactive_cwd, selected_files):
    parent_dir = string.split(active_cwd, os.sep)[-1]
    if parent_dir=='':
        parent_dir = 'root'
    f_md5sum = file(inactive_cwd+os.sep+parent_dir+'.md5sum', 'w')
    for uri in selected_files:
        if gnomevfs.get_file_info(uri).type==gnomevfs.FILE_TYPE_REGULAR:
            f = file(active_cwd+os.sep+uri.short_name, 'rb')
            file_content = f.read()
            f.close()
            md5sum = md5.new(file_content).hexdigest()
            f_md5sum.write('%s  %s\n' % (md5sum, uri.short_name))
    f_md5sum.close()
    return True