def get(self, request, path): if self.path: parent_url = request.build_absolute_uri(reverse('browse:index', kwargs={'path': ''.join(p + '/' for p in path.split('/')[:-2])})) else: parent_url = None subpaths, sort_name, sort_reverse = self.get_subpath_data(request, path) stat = os.stat(self.path_on_disk) context = { 'path': self.path, 'message': request.GET.get('message'), 'parent_url': parent_url, 'subpaths': subpaths, 'stat': statinfo_to_dict(stat), 'additional_headers': { 'Last-Modified': format_date_time(stat.st_mtime), }, 'sort_name': sort_name, 'sort_reverse': sort_reverse, 'column_names': (('name', 'Name'), ('modified', 'Last modified'), ('size', 'Size'), ('owner_name', 'Owner')), 'dataset_submissions': DatasetSubmission.objects.filter(path_on_disk=self.path_on_disk), } return self.render(request, context, 'browse/directory')
def get(self, request, path): if self.path: parent_url = request.build_absolute_uri(reverse('browse:index', kwargs={'path': ''.join(p + '/' for p in path.split('/')[:-2])})) else: parent_url = None subpaths, sort_name, sort_reverse = self.get_subpath_data(request, path) stat = os.stat(self.path_on_disk) context = { 'path': self.path, 'can_submit': self.can_submit(self.path_on_disk), 'message': request.GET.get('message'), 'parent_url': parent_url, 'subpaths': subpaths, 'stat': statinfo_to_dict(stat), 'additional_headers': { 'Last-Modified': format_date_time(stat.st_mtime), }, 'sort_name': sort_name, 'sort_reverse': sort_reverse, 'column_names': (('name', 'Name'), ('modified', 'Last modified'), ('size', 'Size'), ('owner_name', 'Owner')), 'dataset_submissions': DatasetSubmission.objects.filter(path_on_disk=self.path_on_disk), } return self.render(request, context, 'browse/directory')
def get_subpath_data(self, request, path): try: sort_name = request.GET.get('sort') or 'name' sort_function = self.sorts[request.GET.get('sort', 'name')] sort_reverse = {'true': True, 'false': False}[request.GET.get('reverse', 'false')] except KeyError: raise Http404 subpaths = [{'name': name} for name in os.listdir(self.path_on_disk) if not name.startswith('.')] for subpath in subpaths: subpath_on_disk = os.path.join(self.path_on_disk, subpath['name']) try: subpath_stat = os.stat(subpath_on_disk) except OSError, e: if e.errno == errno.ENOENT: subpath['type'] = 'missing' continue raise subpath['path'] = '%s%s' % (self.path, subpath['name']) if self.path else subpath['name'] subpath.update({ 'type': 'dir' if os.path.isdir(subpath_on_disk) else 'file', 'stat': statinfo_to_dict(subpath_stat), 'last_modified': datetime.datetime.fromtimestamp(subpath_stat.st_mtime), 'url': request.build_absolute_uri(reverse('browse:index', kwargs={'path': subpath['path']})), 'link': self.can_read(subpath_on_disk), 'can_read': self.can_read(subpath_on_disk), 'can_write': self.can_write(subpath_on_disk), }) print subpath_on_disk, subpath['link'] try: pw_user = pwd.getpwuid(subpath_stat.st_uid) subpath.update({'owner_name': pw_user.pw_gecos, 'owner_username': pw_user.pw_name}) except KeyError: subpath['owner'] = None if subpath['type'] == 'dir': subpath['url'] += '/' if subpath['link']: subpath['xattr'] = dict(xattr.xattr(subpath_on_disk)) # Only expose user-space extended attributes for k in list(subpath['xattr']): if not k.startswith('user.'): del subpath['xattr'][k] subpath['title'] = subpath['xattr'].get('user.dublincore.title') subpath['description'] = subpath['xattr'].get('user.dublincore.description')
def get_subpath_data(self, request, path): try: sort_name = request.GET.get('sort') or 'name' sort_function = self.sorts[request.GET.get('sort', 'name')] sort_reverse = {'true': True, 'false': False}[request.GET.get('reverse', 'false')] except KeyError: raise Http404 with self.access_error_handler(): subpaths = [{'name': name} for name in os.listdir(self.path_on_disk) if not name.startswith('.')] for subpath in subpaths: subpath_on_disk = os.path.join(self.path_on_disk, subpath['name']) try: subpath_stat = os.stat(subpath_on_disk) except OSError, e: if e.errno == errno.ENOENT: subpath['type'] = 'missing' continue raise a_path=self.path a_name = subpath['name'] logger.info("Path = " + repr(a_path) + ", Name = " + repr(a_name) ) # subpath['path'] = '%s%s' % (self.path, subpath['name']) if self.path else subpath['name'] subpath['path'] = '%s%s' % (self.path, subpath['name']) if self.path else subpath['name'] logger.info('subpath[path]' + str(subpath['path'])) logger.info( 'This directory/file path: ' + str(subpath_on_disk) + ' has the following access rights') logger.info( 'Directroy.py - can_read : ' + str(self.can_read(subpath_on_disk))) logger.info( 'Directroy.py - can_write : ' + str(self.can_write(subpath_on_disk))) subpath.update({ 'type': 'dir' if os.path.isdir(subpath_on_disk) else 'file', 'stat': statinfo_to_dict(subpath_stat), 'last_modified': datetime.datetime.fromtimestamp(subpath_stat.st_mtime), #'url': request.build_absolute_uri(reverse('browse:index', # kwargs={'path': subpath['path'] } # )), 'url': urllib.quote( subpath['name']), 'link': self.can_read(subpath_on_disk), 'can_read': self.can_read(subpath_on_disk), 'can_write': self.can_write(subpath_on_disk), }) logger.info('url[path]' + str(subpath['url'])) print subpath_on_disk, subpath['link'] try: pw_user = pwd.getpwuid(subpath_stat.st_uid) subpath.update({'owner_name': pw_user.pw_gecos, 'owner_username': pw_user.pw_name}) except KeyError: subpath['owner'] = None if subpath['type'] == 'dir': subpath['url'] += '/' #url_sub = subpath['url'] #subpath['url'] = url_sub.encode(sys.getfilesystemencoding())#unicode(subpath['url']) if subpath['link']: subpath['xattr'] = dict(xattr.xattr(subpath_on_disk)) # Only expose user-space extended attributes for k in list(subpath['xattr']): if not k.startswith('user.'): del subpath['xattr'][k] subpath['title'] = subpath['xattr'].get('user.dublincore.title') subpath['description'] = subpath['xattr'].get('user.dublincore.description')