Ticket #1108: sugar-datastore-pep8.patch

File sugar-datastore-pep8.patch, 14.5 KB (added by sascha_silbe, 15 years ago)

PEP8 compliance fixes

  • maint-helper.py

    diff --git a/maint-helper.py b/maint-helper.py
    index 8c64ca2..5ffd7e0 100755
    a b import re 
    2222import datetime
    2323import subprocess
    2424
    25 source_exts = [ '.py', '.c', '.h', '.cpp' ]
     25
     26SOURCE_EXTS = ['.py', '.c', '.h', '.cpp']
     27COPYRIGHT = 'Copyright (C) '
     28
    2629
    2730def is_source(path):
    28     for ext in source_exts:
     31    for ext in SOURCE_EXTS:
    2932        if path.endswith(ext):
    3033            return True
    3134
     35
    3236def get_name_and_version():
    3337    f = open('configure.ac', 'r')
    3438    config = f.read()
    def get_name_and_version(): 
    4044        print 'Cannot find the package name and version.'
    4145        sys.exit(0)
    4246
    43     return [ match.group(2), match.group(1) ]
     47    return (match.group(2), match.group(1))
     48
    4449
    4550def cmd_help():
    4651    print 'Usage: \n\
    maint-helper.py build-snapshot - build a source snapshot \n\ 
    4853maint-helper.py fix-copyright [path] - fix the copyright year \n\
    4954maint-helper.py check-licenses       - check licenses in the source'
    5055
     56
    5157def cmd_build_snapshot():
    52     [ name, version ] = get_name_and_version()
     58    name, version = get_name_and_version()
    5359
    5460    print 'Update git...'
    5561
    def cmd_build_snapshot(): 
    7076
    7177    print 'Update NEWS.sugar...'
    7278
    73     if os.environ.has_key('SUGAR_NEWS'):
     79    if 'SUGAR_NEWS' in os.environ:
    7480        sugar_news_path = os.environ['SUGAR_NEWS']
    7581        if os.path.isfile(sugar_news_path):
    7682            f = open(sugar_news_path, 'r')
    def cmd_build_snapshot(): 
    7985        else:
    8086            sugar_news = ''
    8187
    82         [ name, version ] = get_name_and_version()
     88        name, version = get_name_and_version()
    8389        sugar_news += '%s - %s - %s\n\n' % (name, version, alphatag)
    8490
    8591        f = open('NEWS', 'r')
    def cmd_build_snapshot(): 
    119125
    120126    print 'Done.'
    121127
     128
    122129def check_licenses(path, license, missing):
    123     matchers = { 'LGPL' : 'GNU Lesser General Public',
    124                  'GPL'  : 'GNU General Public License' }
     130    matchers = {'LGPL': 'GNU Lesser General Public',
     131                 'GPL': 'GNU General Public License'}
    125132
    126133    license_file = os.path.join(path, '.license')
    127134    if os.path.isfile(license_file):
    def check_licenses(path, license, missing): 
    156163                    miss_license = False
    157164
    158165                if miss_license:
    159                     if not missing.has_key(license):
     166                    if license not in missing:
    160167                        missing[license] = []
    161168                    missing[license].append(full_path)
    162169
     170
    163171def cmd_check_licenses():
    164172    missing = {}
    165173    check_licenses(os.getcwd(), 'GPL', missing)
    def cmd_check_licenses(): 
    170178            print path
    171179        print '\n'
    172180
    173 COPYRIGHT = 'Copyright (C) '
    174181
    175182def fix_copyright(path):
    176183    for item in os.listdir(path):
    def fix_copyright(path): 
    208215                    f.write(result)
    209216                    f.close()
    210217
     218
    211219def cmd_fix_copyright(path):
    212220    fix_copyright(path)
    213221
     222
    214223if len(sys.argv) < 2:
    215224    cmd_help()
    216225elif sys.argv[1] == 'build-snapshot':
  • src/carquinyol/__init__.py

    diff --git a/src/carquinyol/__init__.py b/src/carquinyol/__init__.py
    index 8b13789..e69de29 100644
    a b  
    1 
  • src/carquinyol/datastore.py

    diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
    index ff3875d..74c75e9 100644
    a b DS_OBJECT_PATH = "/org/laptop/sugar/DataStore" 
    4343
    4444logger = logging.getLogger(DS_LOG_CHANNEL)
    4545
     46
    4647class DataStore(dbus.service.Object):
    4748    """D-Bus API and logic for connecting all the other components.
    48     """
     49    """
     50
    4951    def __init__(self, **options):
    5052        bus_name = dbus.service.BusName(DS_SERVICE,
    5153                                        bus=dbus.SessionBus(),
    class DataStore(dbus.service.Object): 
    214216        for uid in uids:
    215217            entry_path = layoutmanager.get_instance().get_entry_path(uid)
    216218            if not os.path.exists(entry_path):
    217                 logging.warning('Inconsistency detected, returning all entries')
     219                logging.warning(
     220                    'Inconsistency detected, returning all entries')
    218221
    219222                layoutmanager.get_instance().index_updated = False
    220223                self._index_store.close_index()
    class DataStore(dbus.service.Object): 
    293296        self._index_store.delete(uid)
    294297        self._file_store.delete(uid)
    295298        self._metadata_store.delete(uid)
    296        
     299
    297300        entry_path = layoutmanager.get_instance().get_entry_path(uid)
    298301        os.removedirs(entry_path)
    299302
    class DataStore(dbus.service.Object): 
    338341    @dbus.service.signal(DS_DBUS_INTERFACE, signature="a{sv}")
    339342    def Unmounted(self, descriptor):
    340343        pass
    341 
  • src/carquinyol/filestore.py

    diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
    index f88c531..b96c323 100644
    a b import gobject 
    2323
    2424from carquinyol import layoutmanager
    2525
     26
    2627class FileStore(object):
    2728    """Handle the storage of one file per entry.
    2829    """
     30
    2931    # TODO: add protection against store and retrieve operations on entries
    3032    # that are being processed async.
    3133
    3234    def store(self, uid, file_path, transfer_ownership, completion_cb):
    3335        """Store a file for a given entry.
    34            
     36
    3537        """
    3638        dir_path = layoutmanager.get_instance().get_entry_path(uid)
    3739        if not os.path.exists(dir_path):
    class FileStore(object): 
    6870
    6971    def _async_copy(self, file_path, destination_path, completion_cb):
    7072        """Start copying a file asynchronously.
    71        
     73
    7274        """
    7375        logging.debug('FileStore copying from %r to %r' % \
    7476                      (file_path, destination_path))
    class FileStore(object): 
    7678        async_copy.start()
    7779
    7880    def retrieve(self, uid, user_id, extension):
    79         """Place the file associated to a given entry into a directory where the
    80             user can read it. The caller is reponsible for deleting this file.
    81        
     81        """Place the file associated to a given entry into a directory
     82           where the user can read it. The caller is reponsible for
     83           deleting this file.
     84
    8285        """
    8386        dir_path = layoutmanager.get_instance().get_entry_path(uid)
    8487        file_path = os.path.join(dir_path, 'data')
    class FileStore(object): 
    9194        if use_instance_dir:
    9295            if not user_id:
    9396                raise ValueError('Couldnt determine the current user uid.')
    94             destination_dir = os.path.join(os.environ['HOME'], 'isolation', '1',
    95                                           'uid_to_instance_dir', str(user_id))
     97            destination_dir = os.path.join(os.environ['HOME'], 'isolation',
     98                '1', 'uid_to_instance_dir', str(user_id))
    9699        else:
    97100            profile = os.environ.get('SUGAR_PROFILE', 'default')
    98101            destination_dir = os.path.join(os.path.expanduser('~'), '.sugar',
    class FileStore(object): 
    147150
    148151    def delete(self, uid):
    149152        """Remove the file associated to a given entry.
    150        
     153
    151154        """
    152155        dir_path = layoutmanager.get_instance().get_entry_path(uid)
    153156        file_path = os.path.join(dir_path, 'data')
    class FileStore(object): 
    168171        logging.debug('hard linking %r -> %r' % (new_file, existing_file))
    169172        os.link(existing_file, new_file)
    170173
     174
    171175class AsyncCopy(object):
    172176    """Copy a file in chunks in the idle loop.
    173    
     177
    174178    """
    175179    CHUNK_SIZE = 65536
    176180
    class AsyncCopy(object): 
    227231        self.size = stat[6]
    228232
    229233        gobject.idle_add(self._copy_block)
    230 
  • src/carquinyol/indexstore.py

    diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
    index 0f2b982..42c3132 100644
    a b _PROPERTIES_NOT_TO_INDEX = ['timestamp', 'activity_id', 'keep', 'preview'] 
    4444
    4545_MAX_RESULTS = int(2 ** 31 - 1)
    4646
     47
    4748class IndexStore(object):
    4849    """Index metadata and provide rich query facilities on it.
    49     """
     50    """
     51
    5052    def __init__(self):
    5153        self._database = None
    5254        self._flush_timeout = None
    class IndexStore(object): 
    221223
    222224        if query_dict:
    223225            logging.warning('Unknown term(s): %r' % query_dict)
    224        
     226
    225227        return Query(Query.OP_AND, queries)
    226228
    227229    def delete(self, uid):
    class IndexStore(object): 
    239241
    240242    def _flush(self, force=False):
    241243        """Called after any database mutation"""
    242         logging.debug('IndexStore.flush: %r %r' % (force, self._pending_writes))
     244        logging.debug('IndexStore.flush: %r %r' %
     245            (force, self._pending_writes))
    243246
    244247        if self._flush_timeout is not None:
    245248            gobject.source_remove(self._flush_timeout)
    class IndexStore(object): 
    252255        else:
    253256            self._flush_timeout = gobject.timeout_add(_FLUSH_TIMEOUT * 1000,
    254257                                                      self._flush_timeout_cb)
    255 
  • src/carquinyol/layoutmanager.py

    diff --git a/src/carquinyol/layoutmanager.py b/src/carquinyol/layoutmanager.py
    index dc3fde6..a017029 100644
    a b import os 
    1818
    1919MAX_QUERY_LIMIT = 40960
    2020
     21
    2122class LayoutManager(object):
    2223    """Provide the logic about how entries are stored inside the datastore
    2324    directory
    24     """
     25    """
     26
    2527    def __init__(self):
    2628        profile = os.environ.get('SUGAR_PROFILE', 'default')
    2729        base_dir = os.path.join(os.path.expanduser('~'), '.sugar', profile)
    class LayoutManager(object): 
    6567
    6668    def get_checksums_dir(self):
    6769        return os.path.join(self._root_path, 'checksums')
    68  
     70
    6971    def get_queue_path(self):
    7072        return os.path.join(self.get_checksums_dir(), 'queue')
    7173
    class LayoutManager(object): 
    9395                        uids.append(g)
    9496        return uids
    9597
     98
    9699_instance = None
    97100def get_instance():
    98101    global _instance
    99102    if _instance is None:
    100103        _instance = LayoutManager()
    101104    return _instance
    102 
  • src/carquinyol/metadatastore.py

    diff --git a/src/carquinyol/metadatastore.py b/src/carquinyol/metadatastore.py
    index 50981f3..8461ef7 100644
    a b from carquinyol import metadatareader 
    55
    66MAX_SIZE = 256
    77
     8
    89class MetadataStore(object):
     10
    911    def store(self, uid, metadata):
    1012        dir_path = layoutmanager.get_instance().get_entry_path(uid)
    1113        if not os.path.exists(dir_path):
    class MetadataStore(object): 
    2123        metadata['uid'] = uid
    2224        for key, value in metadata.items():
    2325
    24             # Hack to support activities that still pass properties named as for
    25             # example title:text.
     26            # Hack to support activities that still pass properties named as
     27            # for example title:text.
    2628            if ':' in key:
    2729                key = key.split(':', 1)[0]
    2830
    class MetadataStore(object): 
    6163        metadata_path = os.path.join(dir_path, 'metadata')
    6264        property_path = os.path.join(metadata_path, key)
    6365        open(property_path, 'w').write(value)
    64 
  • src/carquinyol/migration.py

    diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
    index 228db2a..02f8e68 100644
    a b  
    1515# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1616
    1717"""Transform one DataStore directory in a newer format.
    18 """ 
     18"""
    1919
    2020import os
    2121import logging
    from carquinyol import layoutmanager 
    2929
    3030DATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
    3131
     32
    3233def migrate_from_0():
    3334    logging.info('Migrating datastore from version 0 to version 1')
    3435
    def migrate_from_0(): 
    5758
    5859    logging.info('Migration finished')
    5960
     61
    6062def _migrate_metadata(root_path, old_root_path, uid):
    6163    dir_path = layoutmanager.get_instance().get_entry_path(uid)
    6264    metadata_path = os.path.join(dir_path, 'metadata')
    def _migrate_metadata(root_path, old_root_path, uid): 
    8890                    'Error while migrating property %s of entry %s: %s\n' % \
    8991                    (key, uid, traceback.format_exc()))
    9092
     93
    9194def _migrate_file(root_path, old_root_path, uid):
    9295    if os.path.exists(os.path.join(old_root_path, uid)):
    9396        dir_path = layoutmanager.get_instance().get_entry_path(uid)
    9497        os.rename(os.path.join(old_root_path, uid),
    9598                  os.path.join(dir_path, 'data'))
    9699
     100
    97101def _migrate_preview(root_path, old_root_path, uid):
    98102    dir_path = layoutmanager.get_instance().get_entry_path(uid)
    99103    metadata_path = os.path.join(dir_path, 'metadata')
    100104    os.rename(os.path.join(old_root_path, 'preview', uid),
    101105              os.path.join(metadata_path, 'preview'))
    102 
  • src/carquinyol/optimizer.py

    diff --git a/src/carquinyol/optimizer.py b/src/carquinyol/optimizer.py
    index f8a2e3e..6cb1374 100644
    a b import gobject 
    2323
    2424from carquinyol import layoutmanager
    2525
     26
    2627class Optimizer(object):
    2728    """Optimizes disk space usage by detecting duplicates and sharing storage.
    2829    """
     30
    2931    def __init__(self, file_store, metadata_store):
    3032        self._file_store = file_store
    3133        self._metadata_store = metadata_store
    class Optimizer(object): 
    9092
    9193    def _create_checksum_dir(self, checksum):
    9294        """Create directory that tracks files with this same checksum.
    93        
     95
    9496        """
    9597        checksums_dir = layoutmanager.get_instance().get_checksums_dir()
    9698        checksum_path = os.path.join(checksums_dir, checksum)
    class Optimizer(object): 
    110112    def _already_linked(self, uid, checksum):
    111113        """Check if this entry's file is already a hard link to the checksums
    112114           dir.
    113        
     115
    114116        """
    115117        checksums_dir = layoutmanager.get_instance().get_checksums_dir()
    116118        checksum_path = os.path.join(checksums_dir, checksum)
    class Optimizer(object): 
    120122        """Process one item in the checksums queue by calculating its checksum,
    121123           checking if there exist already an identical file, and in that case
    122124           substituting its file with a hard link to that pre-existing file.
    123        
     125
    124126        """
    125127        queue_path = layoutmanager.get_instance().get_queue_path()
    126128        queue = os.listdir(queue_path)
    class Optimizer(object): 
    158160
    159161    def _calculate_md5sum(self, path):
    160162        """Calculate the md5 checksum of a given file.
    161        
     163
    162164        """
    163165        popen = subprocess.Popen(['md5sum', path], stdout=subprocess.PIPE)
    164166        stdout, stderr_ = popen.communicate()
    165167        return stdout.split(' ', 1)[0]
    166