~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/volume_manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-06-08 17:31:18 UTC
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100608173118-o8s897ll11rtne99
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
276
276
        return result
277
277
 
278
278
 
 
279
class VolumeDoesNotExist(Exception):
 
280
    """Exception for non existing volumes."""
 
281
 
 
282
    msg = 'DOES_NOT_EXIST'
 
283
 
 
284
    def __init__(self, volume_id):
 
285
        """Create the instance."""
 
286
        super(VolumeDoesNotExist, self).__init__(self.msg, volume_id)
 
287
 
 
288
    def __str__(self):
 
289
        """The error message."""
 
290
        return self.msg
 
291
 
 
292
 
279
293
class VolumeManager(object):
280
294
    """Manages shares and mount points."""
281
295
 
309
323
        if not os.path.exists(self.m.shares_dir_link):
310
324
            self.log.debug('creating Shares symlink: %r -> %r',
311
325
                           self.m.shares_dir_link, self.m.shares_dir)
 
326
            # remove the symlink if it's broken
 
327
            if os.path.islink(self.m.shares_dir_link) and \
 
328
               os.readlink(self.m.shares_dir_link) != self.m.shares_dir:
 
329
                os.remove(self.m.shares_dir_link)
312
330
            os.symlink(self.m.shares_dir, self.m.shares_dir_link)
313
331
        # make the shares_dir read only
314
332
        os.chmod(self.m.shares_dir, 0555)
803
821
        del self.udfs[udf_id]
804
822
        self.m.event_q.push('VM_VOLUME_DELETED', udf)
805
823
 
806
 
    def get_volume(self, id):
 
824
    def get_volume(self, volume_id):
807
825
        """Returns the Share or UDF with the matching id."""
808
 
        volume = self.shares.get(id, None)
809
 
        if volume is None:
810
 
            volume = self.udfs.get(id, None)
811
 
        if volume is None:
812
 
            raise KeyError(id)
 
826
        volume = self.shares.get(volume_id, None)
 
827
        if volume is None:
 
828
            volume = self.udfs.get(volume_id, None)
 
829
        if volume is None:
 
830
            raise VolumeDoesNotExist(volume_id)
813
831
        return volume
814
832
 
815
833
    def get_volumes(self, all_volumes=False):
868
886
                    return
869
887
                # the UDF it's in subscribed state by default
870
888
                subscribe = config.get_user_config().get_udf_autosubscribe()
871
 
                udf = UDF(None, None, os.path.join(udf_path, udf_name), path,
872
 
                          subscribed=subscribe)
 
889
                udf = UDF(None, None,
 
890
                         # suggested_path is always unicode
 
891
                          os.path.join(udf_path, udf_name).decode('utf-8'),
 
892
                          path, subscribed=subscribe)
873
893
                self.marker_udf_map[marker] = udf
874
 
                self.m.action_q.create_udf(udf_path, udf_name, marker)
 
894
                self.m.action_q.create_udf(udf_path.decode('utf-8'),
 
895
                                           udf_name.decode('utf-8'), marker)
875
896
            except Exception, e:
876
897
                self.m.event_q.push('VM_UDF_CREATE_ERROR', path,
877
898
                                    "UNKNOWN_ERROR: %s" % e)
913
934
 
914
935
        """
915
936
        self.log.info('delete_volume: %r', volume_id)
916
 
        try:
917
 
            volume = self.get_volume(volume_id)
918
 
        except KeyError:
919
 
            self.m.event_q.push('VM_VOLUME_DELETE_ERROR', volume_id,
920
 
                                "DOES_NOT_EXIST")
921
 
        else:
922
 
            self.m.action_q.delete_volume(volume.id)
 
937
        volume = self.get_volume(volume_id)
 
938
        self.m.action_q.delete_volume(volume.id)
923
939
 
924
940
    def subscribe_udf(self, udf_id):
925
941
        """Mark the UDF with id as subscribed.