~ubuntu-branches/ubuntu/saucy/isomd5sum/saucy-proposed

« back to all changes in this revision

Viewing changes to pyisomd5sum.c

  • Committer: Package Import Robot
  • Author(s): Ryan Finnie
  • Date: 2012-08-14 04:18:11 UTC
  • mfrom: (1.1.6) (2.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20120814041811-237ybcit9w58ldts
Tags: 1:1.0.9-2
* Switch to debhelper-7-style debian/rules
* debian/control: add XS-Python-Version: all

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2001-2007 Red Hat, Inc.
 
2
 * Copyright (C) 2001-2012 Red Hat, Inc.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
31
31
    { NULL }
32
32
} ;
33
33
 
 
34
/* Call python object with offset and total
 
35
 * If the object returns true return 1 to abort the check
 
36
 */
 
37
int pythonCB(void *cbdata, long long offset, long long total) {
 
38
    PyObject *arglist, *result;
 
39
    int rc;
 
40
 
 
41
    arglist = Py_BuildValue("(LL)", offset, total);
 
42
    result = PyObject_CallObject(cbdata, arglist);
 
43
    Py_DECREF(arglist);
 
44
 
 
45
    if (result == NULL)
 
46
       return 1;
 
47
 
 
48
    rc = PyObject_IsTrue(result);
 
49
    Py_DECREF(result);
 
50
    return (rc > 0);
 
51
}
34
52
 
35
53
static PyObject * doCheckIsoMD5Sum(PyObject * s, PyObject * args) {
 
54
    PyObject *callback = NULL;
36
55
    char *isofile;
37
56
    int rc;
38
57
 
39
 
    if (!PyArg_ParseTuple(args, "s", &isofile))
40
 
        return NULL;
41
 
 
42
 
    rc = mediaCheckFile(isofile, NULL, NULL);
 
58
    if (!PyArg_ParseTuple(args, "s|O", &isofile, &callback))
 
59
        return NULL;
 
60
 
 
61
    if (callback) {
 
62
        if (!PyCallable_Check(callback)) {
 
63
            PyErr_SetString(PyExc_TypeError, "parameter must be callable");
 
64
            return NULL;
 
65
        }
 
66
 
 
67
        rc = mediaCheckFile(isofile, pythonCB, callback);
 
68
        Py_DECREF(callback);
 
69
    } else {
 
70
        rc = mediaCheckFile(isofile, NULL, NULL);
 
71
    }
43
72
 
44
73
    return Py_BuildValue("i", rc);
45
74
}
50
79
    int rc;
51
80
 
52
81
    if (!PyArg_ParseTuple(args, "sii", &isofile, &supported, &forceit))
53
 
        return NULL;
 
82
        return NULL;
54
83
 
55
84
    rc = implantISOFile(isofile, supported, forceit, 1, &errstr);
56
85