Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-10-16 14:01:11 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-10-16 14:01:11 (GMT)
commit6865aaefeb3811bf146dced8ffec41539a877c17 (patch)
treefc3bfce33d64b85a903ea9ba356269628ff24652
parenta09f5d4e4bed8b6d1b8dcfe2aaa287a26bf40cf2 (diff)
More sugar-lint fixes; add HACKING file
-rw-r--r--HACKING15
-rwxr-xr-xmaint-helper.py14
-rw-r--r--src/carquinyol/datastore.py11
-rw-r--r--src/carquinyol/indexstore.py2
-rw-r--r--src/carquinyol/layoutmanager.py2
-rw-r--r--src/carquinyol/metadatareader.c198
-rw-r--r--src/carquinyol/optimizer.py4
7 files changed, 128 insertions, 118 deletions
diff --git a/HACKING b/HACKING
new file mode 100644
index 0000000..5c3a436
--- /dev/null
+++ b/HACKING
@@ -0,0 +1,15 @@
+Before committing
+~~~~~~~~~~~~~~~~~
+All source files need to be passed through sugar-lint[1] command.
+Follow sugar-lint home page instructions and especially
+"Lint files before committing" section.
+
+
+Send patches
+~~~~~~~~~~~~
+Create your patches using "git format" command and send them to all maintainers
+from AUTHORS file with CCing to sugar-devel@lists.sugarlabs.org.
+The easiest way it just using "git send-email" command.
+
+
+[1] http://wiki.sugarlabs.org/go/Activity_Team/Sugar_Lint
diff --git a/maint-helper.py b/maint-helper.py
index 5ffd7e0..2d0537e 100755
--- a/maint-helper.py
+++ b/maint-helper.py
@@ -126,21 +126,21 @@ def cmd_build_snapshot():
print 'Done.'
-def check_licenses(path, license, missing):
+def check_licenses(path, license_text, missing):
matchers = {'LGPL': 'GNU Lesser General Public',
'GPL': 'GNU General Public License'}
license_file = os.path.join(path, '.license')
if os.path.isfile(license_file):
f = open(license_file, 'r')
- license = f.readline().strip()
+ license_text = f.readline().strip()
f.close()
for item in os.listdir(path):
full_path = os.path.join(path, item)
if os.path.isdir(full_path):
- check_licenses(full_path, license, missing)
+ check_licenses(full_path, license_text, missing)
else:
check_source = is_source(item)
@@ -155,7 +155,7 @@ def check_licenses(path, license, missing):
f.close()
miss_license = True
- if source.find(matchers[license]) > 0:
+ if source.find(matchers[license_text]) > 0:
miss_license = False
# Special cases.
@@ -163,9 +163,9 @@ def check_licenses(path, license, missing):
miss_license = False
if miss_license:
- if license not in missing:
- missing[license] = []
- missing[license].append(full_path)
+ if license_text not in missing:
+ missing[license_text] = []
+ missing[license_text].append(full_path)
def cmd_check_licenses():
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 28d7247..837de35 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -15,6 +15,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# pylint fails on @debian's arguments
+# pylint: disable=C0322
+
import logging
import uuid
import time
@@ -207,10 +210,10 @@ class DataStore(dbus.service.Object):
self._metadata_store.store(uid, props)
self._index_store.store(uid, props)
self._file_store.store(uid, file_path, transfer_ownership,
- lambda *args: self._create_completion_cb(async_cb,
+ lambda * args: self._create_completion_cb(async_cb,
async_err_cb,
uid,
- *args))
+ * args))
@dbus.service.signal(DS_DBUS_INTERFACE, signature="s")
def Created(self, uid):
@@ -267,10 +270,10 @@ class DataStore(dbus.service.Object):
(not file_path or os.path.exists(file_path)):
self._optimizer.remove(uid)
self._file_store.store(uid, file_path, transfer_ownership,
- lambda *args: self._update_completion_cb(async_cb,
+ lambda * args: self._update_completion_cb(async_cb,
async_err_cb,
uid,
- *args))
+ * args))
@dbus.service.signal(DS_DBUS_INTERFACE, signature="s")
def Updated(self, uid):
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index b8088b2..dc721e7 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -261,7 +261,7 @@ class IndexStore(object):
postings = self._database.postlist(_PREFIX_FULL_VALUE + \
_PREFIX_UID + uid)
try:
- postlist_item = postings.next()
+ __ = postings.next()
except StopIteration:
return False
return True
diff --git a/src/carquinyol/layoutmanager.py b/src/carquinyol/layoutmanager.py
index 07f5521..3179a98 100644
--- a/src/carquinyol/layoutmanager.py
+++ b/src/carquinyol/layoutmanager.py
@@ -106,6 +106,8 @@ class LayoutManager(object):
return True
_instance = None
+
+
def get_instance():
global _instance
if _instance is None:
diff --git a/src/carquinyol/metadatareader.c b/src/carquinyol/metadatareader.c
index 454c8c3..d053a22 100644
--- a/src/carquinyol/metadatareader.c
+++ b/src/carquinyol/metadatareader.c
@@ -8,40 +8,38 @@
static PyObject *byte_array_type = NULL;
int
-add_property(const char *metadata_path, char *property_name, PyObject *dict,
- int must_exist)
-{
+add_property (const char *metadata_path, char *property_name, PyObject * dict,
+ int must_exist) {
int file_path_size;
char *file_path = NULL;
FILE *file = NULL;
long file_size;
- char *value_buf = NULL;
+ char *value_buf = NULL;
PyObject *value = NULL;
struct stat file_stat;
// Build path of the property file
- file_path_size = strlen(metadata_path) + 1 + strlen(property_name) + 1;
- file_path = PyMem_Malloc(file_path_size);
- if (file_path == NULL) {
- PyErr_NoMemory();
+ file_path_size = strlen (metadata_path) + 1 + strlen (property_name) + 1;
+ file_path = PyMem_Malloc (file_path_size);
+ if (file_path == NULL) {
+ PyErr_NoMemory ();
return 0;
- }
+ }
snprintf (file_path, file_path_size, "%s/%s", metadata_path, property_name);
- if ((!must_exist) && (stat(file_path, &file_stat) != 0)) {
- PyMem_Free(file_path);
+ if ((!must_exist) && (stat (file_path, &file_stat) != 0)) {
+ PyMem_Free (file_path);
return 1;
}
- file = fopen(file_path, "r");
+ file = fopen (file_path, "r");
if (file == NULL) {
- char buf[256];
- snprintf(buf, sizeof(buf), "Cannot open property file %s: %s",
- file_path, strerror(errno));
- PyErr_SetString(PyExc_IOError, buf);
+ char buf[256];
+ snprintf (buf, sizeof (buf), "Cannot open property file %s: %s",
+ file_path, strerror (errno));
+ PyErr_SetString (PyExc_IOError, buf);
goto cleanup;
}
-
// Get file size
fseek (file, 0, SEEK_END);
file_size = ftell (file);
@@ -49,166 +47,160 @@ add_property(const char *metadata_path, char *property_name, PyObject *dict,
if (file_size == 0) {
// Empty property
- fclose(file);
+ fclose (file);
file = NULL;
- value = PyString_FromString("");
+ value = PyString_FromString ("");
if (value == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "Failed to convert value to python string");
+ PyErr_SetString (PyExc_ValueError,
+ "Failed to convert value to python string");
goto cleanup;
}
} else {
if (file_size > MAX_PROPERTY_LENGTH) {
- PyErr_SetString(PyExc_ValueError, "Property file too big");
+ PyErr_SetString (PyExc_ValueError, "Property file too big");
goto cleanup;
}
-
// Read the whole file
- value_buf = PyMem_Malloc(file_size);
- if (value_buf == NULL) {
- PyErr_NoMemory();
+ value_buf = PyMem_Malloc (file_size);
+ if (value_buf == NULL) {
+ PyErr_NoMemory ();
goto cleanup;
- }
- long read_size = fread(value_buf, 1, file_size, file);
+ }
+ long read_size = fread (value_buf, 1, file_size, file);
if (read_size < file_size) {
- char buf[256];
- snprintf(buf, sizeof(buf),
- "Error while reading property file %s", file_path);
- PyErr_SetString(PyExc_IOError, buf);
+ char buf[256];
+ snprintf (buf, sizeof (buf),
+ "Error while reading property file %s", file_path);
+ PyErr_SetString (PyExc_IOError, buf);
goto cleanup;
}
- fclose(file);
+ fclose (file);
file = NULL;
// Convert value to dbus.ByteArray
- PyObject *args = Py_BuildValue("(s#)", value_buf, file_size);
+ PyObject *args = Py_BuildValue ("(s#)", value_buf, file_size);
- PyMem_Free(value_buf);
+ PyMem_Free (value_buf);
value_buf = NULL;
- value = PyObject_CallObject(byte_array_type, args);
- Py_DECREF(args);
+ value = PyObject_CallObject (byte_array_type, args);
+ Py_DECREF (args);
if (value == NULL) {
- PyErr_SetString(PyExc_ValueError,
- "Failed to convert value to dbus.ByteArray");
+ PyErr_SetString (PyExc_ValueError,
+ "Failed to convert value to dbus.ByteArray");
goto cleanup;
}
}
// Add property to the metadata dict
- if (PyDict_SetItemString(dict, property_name, value) == -1) {
- PyErr_SetString(PyExc_ValueError,
- "Failed to add property to dictionary");
+ if (PyDict_SetItemString (dict, property_name, value) == -1) {
+ PyErr_SetString (PyExc_ValueError,
+ "Failed to add property to dictionary");
goto cleanup;
}
- Py_DECREF(value);
- PyMem_Free(file_path);
+ Py_DECREF (value);
+ PyMem_Free (file_path);
return 1;
-cleanup:
+ cleanup:
if (file_path) {
- PyMem_Free(file_path);
+ PyMem_Free (file_path);
}
if (value_buf) {
- PyMem_Free(value_buf);
+ PyMem_Free (value_buf);
}
if (file) {
- fclose(file);
+ fclose (file);
}
if (value) {
- Py_DECREF(value);
+ Py_DECREF (value);
}
- return 0;
+ return 0;
}
-static PyObject *
-read_from_properties_list (const char *metadata_path, PyObject *properties)
-{
- PyObject *dict = PyDict_New();
+static PyObject *read_from_properties_list (const char *metadata_path,
+ PyObject * properties) {
+ PyObject *dict = PyDict_New ();
int i;
- for (i = 0; i < PyList_Size(properties); i++) {
- PyObject *property = PyList_GetItem(properties, i);
+ for (i = 0; i < PyList_Size (properties); i++) {
+ PyObject *property = PyList_GetItem (properties, i);
char *property_name = PyString_AsString (property);
- if (add_property(metadata_path, property_name, dict, 0) == 0)
+ if (add_property (metadata_path, property_name, dict, 0) == 0)
goto cleanup;
}
return dict;
-cleanup:
+ cleanup:
if (dict) {
- Py_DECREF(dict);
+ Py_DECREF (dict);
}
- return NULL;
+ return NULL;
}
-static PyObject *
-read_all_properties (const char *metadata_path)
-{
- PyObject *dict = PyDict_New();
- DIR *dir_stream = NULL;
- struct dirent *dir_entry = NULL;
+static PyObject *read_all_properties (const char *metadata_path) {
+ PyObject *dict = PyDict_New ();
+ DIR *dir_stream = NULL;
+ struct dirent *dir_entry = NULL;
dir_stream = opendir (metadata_path);
- if (dir_stream == NULL) {
- char buf[256];
- snprintf(buf, sizeof(buf), "Couldn't open metadata directory %s",
- metadata_path);
- PyErr_SetString(PyExc_IOError, buf);
+ if (dir_stream == NULL) {
+ char buf[256];
+ snprintf (buf, sizeof (buf), "Couldn't open metadata directory %s",
+ metadata_path);
+ PyErr_SetString (PyExc_IOError, buf);
goto cleanup;
- }
+ }
- dir_entry = readdir(dir_stream);
+ dir_entry = readdir (dir_stream);
while (dir_entry != NULL) {
// Skip . and ..
if (dir_entry->d_name[0] == '.' &&
- (strlen(dir_entry->d_name) == 1 ||
- (dir_entry->d_name[1] == '.' &&
- strlen(dir_entry->d_name) == 2)))
- goto next_property;
+ (strlen (dir_entry->d_name) == 1 ||
+ (dir_entry->d_name[1] == '.' &&
+ strlen (dir_entry->d_name) == 2)))
+ goto next_property;
- if (add_property(metadata_path, dir_entry->d_name, dict, 1) == 0)
+ if (add_property (metadata_path, dir_entry->d_name, dict, 1) == 0)
goto cleanup;
- next_property:
- dir_entry = readdir(dir_stream);
+ next_property:
+ dir_entry = readdir (dir_stream);
}
- closedir(dir_stream);
+ closedir (dir_stream);
return dict;
-cleanup:
+ cleanup:
if (dict) {
- Py_DECREF(dict);
+ Py_DECREF (dict);
}
if (dir_stream) {
- closedir(dir_stream);
- }
- return NULL;
+ closedir (dir_stream);
+ }
+ return NULL;
}
-static PyObject *
-metadatareader_retrieve(PyObject *unused, PyObject *args)
-{
+static PyObject *metadatareader_retrieve (PyObject * unused, PyObject * args) {
PyObject *dict = NULL;
PyObject *properties = NULL;
const char *metadata_path = NULL;
- if (!PyArg_ParseTuple(args, "sO:retrieve", &metadata_path, &properties))
+ if (!PyArg_ParseTuple (args, "sO:retrieve", &metadata_path, &properties))
return NULL;
- if ((properties != Py_None) && (PyList_Size(properties) > 0)) {
- dict = read_from_properties_list(metadata_path, properties);
+ if ((properties != Py_None) && (PyList_Size (properties) > 0)) {
+ dict = read_from_properties_list (metadata_path, properties);
} else {
- dict = read_all_properties(metadata_path);
+ dict = read_all_properties (metadata_path);
}
return dict;
@@ -216,18 +208,16 @@ metadatareader_retrieve(PyObject *unused, PyObject *args)
static PyMethodDef metadatareader_functions[] = {
{"retrieve", metadatareader_retrieve, METH_VARARGS,
- PyDoc_STR("Read a dictionary from a directory with a single file " \
- "(containing the content) per key")},
+ PyDoc_STR
+ ("Read a dictionary from a directory with a single file "
+ "(containing the content) per key")},
{NULL, NULL, 0, NULL}
};
-PyMODINIT_FUNC
-initmetadatareader(void)
-{
- PyObject* mod;
- mod = Py_InitModule("metadatareader", metadatareader_functions);
-
- PyObject *dbus_module = PyImport_ImportModule("dbus");
- byte_array_type = PyObject_GetAttrString(dbus_module, "ByteArray");
-}
+PyMODINIT_FUNC initmetadatareader (void) {
+ PyObject *mod;
+ mod = Py_InitModule ("metadatareader", metadatareader_functions);
+ PyObject *dbus_module = PyImport_ImportModule ("dbus");
+ byte_array_type = PyObject_GetAttrString (dbus_module, "ByteArray");
+}
diff --git a/src/carquinyol/optimizer.py b/src/carquinyol/optimizer.py
index 2b6ce29..c038c2b 100644
--- a/src/carquinyol/optimizer.py
+++ b/src/carquinyol/optimizer.py
@@ -163,5 +163,5 @@ class Optimizer(object):
"""
popen = subprocess.Popen(['md5sum', path], stdout=subprocess.PIPE)
- stdout, stderr_ = popen.communicate()
- return stdout.split(' ', 1)[0]
+ stdout, __ = popen.communicate()
+ return str(stdout).split(' ', 1)[0]