def check_link_path(self): if self.parent: if not path_contains(self.parent.get_path(), self.link_to_path,real_path=False): raise Exception('Subshare must be under the real share.') elif self.link_to_path: test_path(self.link_to_path,allow_absolute=True) if not paths_contain(settings.LINK_TO_DIRECTORIES,self.link_to_path): raise Exception('Path not allowed.')
def check_link_path(self): if self.parent: if not path_contains(self.parent.get_path(), self.link_to_path, real_path=False): raise Exception('Subshare must be under the real share.') elif self.link_to_path: test_path(self.link_to_path, allow_absolute=True) if not paths_contain(settings.LINK_TO_DIRECTORIES, self.link_to_path): raise Exception('Path not allowed.')
def analyze_path(self, path): match = re.match('/(?P<share>[a-zA-Z0-9]{15})(?:/(?P<subpath>.*))', path) try: matches = match.groupdict() if not matches.has_key('share'): raise WrapperException('analyze_path: Bad key: %s' % path) share = Share.objects.get(id=matches['share']) # share_path = get_share_meta(matches['share'])['path'] if matches.has_key('subpath'): try: test_path(matches['subpath']) except: raise WrapperException('Illegal subpath: %s' % matches['subpath']) path = join(share.get_path(), match.group('subpath')) else: path = share.get_path() return {'share':share,'path':path} except WrapperException, e: raise e
def clean_link_to_path(self): path = self.cleaned_data['link_to_path'] if path == '' or not path: path = None if path: try: test_path(path,allow_absolute=True) except: raise forms.ValidationError('Bad path: "%s"'%path) if not os.path.isdir(path): raise forms.ValidationError('Path: "%s" does not exist'%path) if not paths_contain(settings.LINK_TO_DIRECTORIES,path): raise forms.ValidationError('Path not allowed.') if self.the_instance: if self.the_instance.link_to_path and not path: raise forms.ValidationError('It is not possible to change a linked share to a regular share.') if not self.the_instance.link_to_path and path: raise forms.ValidationError('It is not possible to change a regular share to a linked share.') return path
def analyze_path(self, path): match = re.match('/(?P<share>[a-zA-Z0-9]{15})(?:/(?P<subpath>.*))', path) try: matches = match.groupdict() if not matches.has_key('share'): raise WrapperException('analyze_path: Bad key: %s' % path) share = Share.objects.get(id=matches['share']) # share_path = get_share_meta(matches['share'])['path'] if matches.has_key('subpath'): try: test_path(matches['subpath']) except: raise WrapperException('Illegal subpath: %s' % matches['subpath']) path = join(share.get_path(), match.group('subpath')) else: path = share.get_path() return {'share': share, 'path': path} except WrapperException, e: raise e
def clean_link_to_path(self): path = self.cleaned_data['link_to_path'] if path == '' or not path: path = None if path: try: test_path(path, allow_absolute=True) except: raise forms.ValidationError('Bad path: "%s"' % path) if not os.path.isdir(path): raise forms.ValidationError('Path: "%s" does not exist' % path) if not paths_contain(settings.LINK_TO_DIRECTORIES, path): raise forms.ValidationError('Path not allowed.') if self.the_instance: if self.the_instance.link_to_path and not path: raise forms.ValidationError( 'It is not possible to change a linked share to a regular share.' ) if not self.the_instance.link_to_path and path: raise forms.ValidationError( 'It is not possible to change a regular share to a linked share.' ) return path
def directory_size(self, request, *args, **kwargs): share = self.get_object() subdir = request.query_params.get('subdir','') test_path(subdir,share=share) size = du(os.path.join(share.get_path(),subdir)) return Response({'share':share.id,'subdir':subdir,'size':size})