Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-07-29 16:13:07 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-07-29 16:13:07 (GMT)
commit4986f3697daccaa6adac500664f78dcfa56d719b (patch)
treeb63cc79a7fae664858fe248fdfd18db20c7d8b79
parentdb8beceeae50f2f7e9c7e619d3f90c703a232610 (diff)
PEP8 fixes (silbe) #1108
-rwxr-xr-xmaint-helper.py29
-rw-r--r--src/carquinyol/__init__.py1
-rw-r--r--src/carquinyol/datastore.py10
-rw-r--r--src/carquinyol/filestore.py23
-rw-r--r--src/carquinyol/indexstore.py10
-rw-r--r--src/carquinyol/layoutmanager.py8
-rw-r--r--src/carquinyol/metadatastore.py7
-rw-r--r--src/carquinyol/migration.py7
-rw-r--r--src/carquinyol/optimizer.py11
9 files changed, 64 insertions, 42 deletions
diff --git a/maint-helper.py b/maint-helper.py
index 8c64ca2..5ffd7e0 100755
--- a/maint-helper.py
+++ b/maint-helper.py
@@ -22,13 +22,17 @@ import re
import datetime
import subprocess
-source_exts = [ '.py', '.c', '.h', '.cpp' ]
+
+SOURCE_EXTS = ['.py', '.c', '.h', '.cpp']
+COPYRIGHT = 'Copyright (C) '
+
def is_source(path):
- for ext in source_exts:
+ for ext in SOURCE_EXTS:
if path.endswith(ext):
return True
+
def get_name_and_version():
f = open('configure.ac', 'r')
config = f.read()
@@ -40,7 +44,8 @@ def get_name_and_version():
print 'Cannot find the package name and version.'
sys.exit(0)
- return [ match.group(2), match.group(1) ]
+ return (match.group(2), match.group(1))
+
def cmd_help():
print 'Usage: \n\
@@ -48,8 +53,9 @@ maint-helper.py build-snapshot - build a source snapshot \n\
maint-helper.py fix-copyright [path] - fix the copyright year \n\
maint-helper.py check-licenses - check licenses in the source'
+
def cmd_build_snapshot():
- [ name, version ] = get_name_and_version()
+ name, version = get_name_and_version()
print 'Update git...'
@@ -70,7 +76,7 @@ def cmd_build_snapshot():
print 'Update NEWS.sugar...'
- if os.environ.has_key('SUGAR_NEWS'):
+ if 'SUGAR_NEWS' in os.environ:
sugar_news_path = os.environ['SUGAR_NEWS']
if os.path.isfile(sugar_news_path):
f = open(sugar_news_path, 'r')
@@ -79,7 +85,7 @@ def cmd_build_snapshot():
else:
sugar_news = ''
- [ name, version ] = get_name_and_version()
+ name, version = get_name_and_version()
sugar_news += '%s - %s - %s\n\n' % (name, version, alphatag)
f = open('NEWS', 'r')
@@ -119,9 +125,10 @@ def cmd_build_snapshot():
print 'Done.'
+
def check_licenses(path, license, missing):
- matchers = { 'LGPL' : 'GNU Lesser General Public',
- 'GPL' : 'GNU General Public License' }
+ matchers = {'LGPL': 'GNU Lesser General Public',
+ 'GPL': 'GNU General Public License'}
license_file = os.path.join(path, '.license')
if os.path.isfile(license_file):
@@ -156,10 +163,11 @@ def check_licenses(path, license, missing):
miss_license = False
if miss_license:
- if not missing.has_key(license):
+ if license not in missing:
missing[license] = []
missing[license].append(full_path)
+
def cmd_check_licenses():
missing = {}
check_licenses(os.getcwd(), 'GPL', missing)
@@ -170,7 +178,6 @@ def cmd_check_licenses():
print path
print '\n'
-COPYRIGHT = 'Copyright (C) '
def fix_copyright(path):
for item in os.listdir(path):
@@ -208,9 +215,11 @@ def fix_copyright(path):
f.write(result)
f.close()
+
def cmd_fix_copyright(path):
fix_copyright(path)
+
if len(sys.argv) < 2:
cmd_help()
elif sys.argv[1] == 'build-snapshot':
diff --git a/src/carquinyol/__init__.py b/src/carquinyol/__init__.py
index 8b13789..e69de29 100644
--- a/src/carquinyol/__init__.py
+++ b/src/carquinyol/__init__.py
@@ -1 +0,0 @@
-
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index ff3875d..74c75e9 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -43,9 +43,11 @@ DS_OBJECT_PATH = "/org/laptop/sugar/DataStore"
logger = logging.getLogger(DS_LOG_CHANNEL)
+
class DataStore(dbus.service.Object):
"""D-Bus API and logic for connecting all the other components.
- """
+ """
+
def __init__(self, **options):
bus_name = dbus.service.BusName(DS_SERVICE,
bus=dbus.SessionBus(),
@@ -214,7 +216,8 @@ class DataStore(dbus.service.Object):
for uid in uids:
entry_path = layoutmanager.get_instance().get_entry_path(uid)
if not os.path.exists(entry_path):
- logging.warning('Inconsistency detected, returning all entries')
+ logging.warning(
+ 'Inconsistency detected, returning all entries')
layoutmanager.get_instance().index_updated = False
self._index_store.close_index()
@@ -293,7 +296,7 @@ class DataStore(dbus.service.Object):
self._index_store.delete(uid)
self._file_store.delete(uid)
self._metadata_store.delete(uid)
-
+
entry_path = layoutmanager.get_instance().get_entry_path(uid)
os.removedirs(entry_path)
@@ -338,4 +341,3 @@ class DataStore(dbus.service.Object):
@dbus.service.signal(DS_DBUS_INTERFACE, signature="a{sv}")
def Unmounted(self, descriptor):
pass
-
diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
index f88c531..b96c323 100644
--- a/src/carquinyol/filestore.py
+++ b/src/carquinyol/filestore.py
@@ -23,15 +23,17 @@ import gobject
from carquinyol import layoutmanager
+
class FileStore(object):
"""Handle the storage of one file per entry.
"""
+
# TODO: add protection against store and retrieve operations on entries
# that are being processed async.
def store(self, uid, file_path, transfer_ownership, completion_cb):
"""Store a file for a given entry.
-
+
"""
dir_path = layoutmanager.get_instance().get_entry_path(uid)
if not os.path.exists(dir_path):
@@ -68,7 +70,7 @@ class FileStore(object):
def _async_copy(self, file_path, destination_path, completion_cb):
"""Start copying a file asynchronously.
-
+
"""
logging.debug('FileStore copying from %r to %r' % \
(file_path, destination_path))
@@ -76,9 +78,10 @@ class FileStore(object):
async_copy.start()
def retrieve(self, uid, user_id, extension):
- """Place the file associated to a given entry into a directory where the
- user can read it. The caller is reponsible for deleting this file.
-
+ """Place the file associated to a given entry into a directory
+ where the user can read it. The caller is reponsible for
+ deleting this file.
+
"""
dir_path = layoutmanager.get_instance().get_entry_path(uid)
file_path = os.path.join(dir_path, 'data')
@@ -91,8 +94,8 @@ class FileStore(object):
if use_instance_dir:
if not user_id:
raise ValueError('Couldnt determine the current user uid.')
- destination_dir = os.path.join(os.environ['HOME'], 'isolation', '1',
- 'uid_to_instance_dir', str(user_id))
+ destination_dir = os.path.join(os.environ['HOME'], 'isolation',
+ '1', 'uid_to_instance_dir', str(user_id))
else:
profile = os.environ.get('SUGAR_PROFILE', 'default')
destination_dir = os.path.join(os.path.expanduser('~'), '.sugar',
@@ -147,7 +150,7 @@ class FileStore(object):
def delete(self, uid):
"""Remove the file associated to a given entry.
-
+
"""
dir_path = layoutmanager.get_instance().get_entry_path(uid)
file_path = os.path.join(dir_path, 'data')
@@ -168,9 +171,10 @@ class FileStore(object):
logging.debug('hard linking %r -> %r' % (new_file, existing_file))
os.link(existing_file, new_file)
+
class AsyncCopy(object):
"""Copy a file in chunks in the idle loop.
-
+
"""
CHUNK_SIZE = 65536
@@ -227,4 +231,3 @@ class AsyncCopy(object):
self.size = stat[6]
gobject.idle_add(self._copy_block)
-
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 0f2b982..42c3132 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -44,9 +44,11 @@ _PROPERTIES_NOT_TO_INDEX = ['timestamp', 'activity_id', 'keep', 'preview']
_MAX_RESULTS = int(2 ** 31 - 1)
+
class IndexStore(object):
"""Index metadata and provide rich query facilities on it.
- """
+ """
+
def __init__(self):
self._database = None
self._flush_timeout = None
@@ -221,7 +223,7 @@ class IndexStore(object):
if query_dict:
logging.warning('Unknown term(s): %r' % query_dict)
-
+
return Query(Query.OP_AND, queries)
def delete(self, uid):
@@ -239,7 +241,8 @@ class IndexStore(object):
def _flush(self, force=False):
"""Called after any database mutation"""
- logging.debug('IndexStore.flush: %r %r' % (force, self._pending_writes))
+ logging.debug('IndexStore.flush: %r %r' %
+ (force, self._pending_writes))
if self._flush_timeout is not None:
gobject.source_remove(self._flush_timeout)
@@ -252,4 +255,3 @@ class IndexStore(object):
else:
self._flush_timeout = gobject.timeout_add(_FLUSH_TIMEOUT * 1000,
self._flush_timeout_cb)
-
diff --git a/src/carquinyol/layoutmanager.py b/src/carquinyol/layoutmanager.py
index dc3fde6..a017029 100644
--- a/src/carquinyol/layoutmanager.py
+++ b/src/carquinyol/layoutmanager.py
@@ -18,10 +18,12 @@ import os
MAX_QUERY_LIMIT = 40960
+
class LayoutManager(object):
"""Provide the logic about how entries are stored inside the datastore
directory
- """
+ """
+
def __init__(self):
profile = os.environ.get('SUGAR_PROFILE', 'default')
base_dir = os.path.join(os.path.expanduser('~'), '.sugar', profile)
@@ -65,7 +67,7 @@ class LayoutManager(object):
def get_checksums_dir(self):
return os.path.join(self._root_path, 'checksums')
-
+
def get_queue_path(self):
return os.path.join(self.get_checksums_dir(), 'queue')
@@ -93,10 +95,10 @@ class LayoutManager(object):
uids.append(g)
return uids
+
_instance = None
def get_instance():
global _instance
if _instance is None:
_instance = LayoutManager()
return _instance
-
diff --git a/src/carquinyol/metadatastore.py b/src/carquinyol/metadatastore.py
index 50981f3..8461ef7 100644
--- a/src/carquinyol/metadatastore.py
+++ b/src/carquinyol/metadatastore.py
@@ -5,7 +5,9 @@ from carquinyol import metadatareader
MAX_SIZE = 256
+
class MetadataStore(object):
+
def store(self, uid, metadata):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
if not os.path.exists(dir_path):
@@ -21,8 +23,8 @@ class MetadataStore(object):
metadata['uid'] = uid
for key, value in metadata.items():
- # Hack to support activities that still pass properties named as for
- # example title:text.
+ # Hack to support activities that still pass properties named as
+ # for example title:text.
if ':' in key:
key = key.split(':', 1)[0]
@@ -61,4 +63,3 @@ class MetadataStore(object):
metadata_path = os.path.join(dir_path, 'metadata')
property_path = os.path.join(metadata_path, key)
open(property_path, 'w').write(value)
-
diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
index 228db2a..02f8e68 100644
--- a/src/carquinyol/migration.py
+++ b/src/carquinyol/migration.py
@@ -15,7 +15,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""Transform one DataStore directory in a newer format.
-"""
+"""
import os
import logging
@@ -29,6 +29,7 @@ from carquinyol import layoutmanager
DATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
+
def migrate_from_0():
logging.info('Migrating datastore from version 0 to version 1')
@@ -57,6 +58,7 @@ def migrate_from_0():
logging.info('Migration finished')
+
def _migrate_metadata(root_path, old_root_path, uid):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
metadata_path = os.path.join(dir_path, 'metadata')
@@ -88,15 +90,16 @@ def _migrate_metadata(root_path, old_root_path, uid):
'Error while migrating property %s of entry %s: %s\n' % \
(key, uid, traceback.format_exc()))
+
def _migrate_file(root_path, old_root_path, uid):
if os.path.exists(os.path.join(old_root_path, uid)):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
os.rename(os.path.join(old_root_path, uid),
os.path.join(dir_path, 'data'))
+
def _migrate_preview(root_path, old_root_path, uid):
dir_path = layoutmanager.get_instance().get_entry_path(uid)
metadata_path = os.path.join(dir_path, 'metadata')
os.rename(os.path.join(old_root_path, 'preview', uid),
os.path.join(metadata_path, 'preview'))
-
diff --git a/src/carquinyol/optimizer.py b/src/carquinyol/optimizer.py
index f8a2e3e..6cb1374 100644
--- a/src/carquinyol/optimizer.py
+++ b/src/carquinyol/optimizer.py
@@ -23,9 +23,11 @@ import gobject
from carquinyol import layoutmanager
+
class Optimizer(object):
"""Optimizes disk space usage by detecting duplicates and sharing storage.
"""
+
def __init__(self, file_store, metadata_store):
self._file_store = file_store
self._metadata_store = metadata_store
@@ -90,7 +92,7 @@ class Optimizer(object):
def _create_checksum_dir(self, checksum):
"""Create directory that tracks files with this same checksum.
-
+
"""
checksums_dir = layoutmanager.get_instance().get_checksums_dir()
checksum_path = os.path.join(checksums_dir, checksum)
@@ -110,7 +112,7 @@ class Optimizer(object):
def _already_linked(self, uid, checksum):
"""Check if this entry's file is already a hard link to the checksums
dir.
-
+
"""
checksums_dir = layoutmanager.get_instance().get_checksums_dir()
checksum_path = os.path.join(checksums_dir, checksum)
@@ -120,7 +122,7 @@ class Optimizer(object):
"""Process one item in the checksums queue by calculating its checksum,
checking if there exist already an identical file, and in that case
substituting its file with a hard link to that pre-existing file.
-
+
"""
queue_path = layoutmanager.get_instance().get_queue_path()
queue = os.listdir(queue_path)
@@ -158,9 +160,8 @@ class Optimizer(object):
def _calculate_md5sum(self, path):
"""Calculate the md5 checksum of a given file.
-
+
"""
popen = subprocess.Popen(['md5sum', path], stdout=subprocess.PIPE)
stdout, stderr_ = popen.communicate()
return stdout.split(' ', 1)[0]
-