def __init__(self, location=None, base_url=None): """ Initialize a Git repository or open an existing one. @param location: path where to create and open the repository """ if not location: location = getattr(settings, 'GIT_STORAGE_ROOT', "") if not location: raise ImproperlyConfigured("GIT_STORAGE_ROOT is required") self.base_location = location self.location = abspathu(self.base_location) if base_url is None: try: base_url = settings.GIT_STORAGE_URL except AttributeError: base_url = None self.base_url = base_url # Create the repository as necessary if not os.path.exists(location): self._create() # Open the repository with our class self.repository = wrappers.Repository(self.location) assert self.repository.is_bare # Author of the following commits self.author_signature = self.repository.default_signature
def __init__(self, location=None, base_url=None): if location is None: location = settings.MEDIA_ROOT self.base_location = location self.location = abspathu(self.base_location) if base_url is None: base_url = settings.MEDIA_URL self.base_url = base_url
def test_override_static_root(self): """ Overriding the STATIC_ROOT setting should be reflected in the location attribute of django.contrib.staticfiles.storage.staticfiles_storage. """ with self.settings(STATIC_ROOT='/tmp/test'): self.assertEqual(staticfiles_storage.location, abspathu('/tmp/test'))
def __init__(self, location=None, base_url=None, media_root='', media_url=''): if location is None: location = media_root self.base_location = location self.location = abspathu(self.base_location) if base_url is None: base_url = media_url self.base_url = base_url
def remove_missing_files(): from django.utils._os import abspathu location = abspathu(UploadFileField.get_location()) for (dirpath, dirnames, filenames) in os.walk(location): for name in filenames: fullpath = os.path.join(dirpath, name) if not UploadFile.objects.filter( file=fullpath.replace(location + '/', '')).exists(): os.remove(fullpath)
def upload_images(*args, base_bucket_path=""): images_to_upload = [] for image in args: abs_path = abspathu(settings.MEDIA_ROOT) bucket_path = abspathu(image['file']) if abs_path in bucket_path: bucket_path = bucket_path[len(abs_path):] bucket_path = bucket_path.replace('\\', '/') filename = os.path.basename(image['file']) filepath = os.path.dirname(image['file']) try: image_descriptor = Image.open(image['file']) except IOError: continue content_type = Image.MIME.get(image_descriptor.format) or 'image/png' del image_descriptor if 'sizes' in image: for size_name, size_data in image['sizes'].items(): resize_name = "%s_%s" % (size_name, filename) out = (os.path.join(filepath, resize_name)).replace('\\', '/') resize(image['file'], out=out, **size_data) images_to_upload.append({ 'file': out, 'bucket_path': "%s%s%s" % (base_bucket_path, size_name, bucket_path), 'content_type': content_type, }) images_to_upload.append({ 'file': image['file'], 'bucket_path': "%soriginal%s" % (base_bucket_path, bucket_path), 'content_type': content_type }) upload_to_S3(*images_to_upload) return [image['bucket_path'] for image in images_to_upload]
def __init__(self, location=None, base_url=None, file_permissions_mode=None): if location is None: location = settings.MEDIA_ROOT self.base_location = location self.location = abspathu(self.base_location) if base_url is None: base_url = settings.MEDIA_URL self.base_url = base_url self.file_permissions_mode = ( file_permissions_mode if file_permissions_mode is not None else settings.FILE_UPLOAD_PERMISSIONS )
def __init__(self, root=None, base_url=None, file_permissions_mode=None, directory_permissions_mode=None): if root is None: root = settings.MEDIA_ROOT self.root = abspathu(root) if base_url is None: base_url = settings.MEDIA_URL self.base_url = base_url if file_permissions_mode is not None: self.file_permissions_mode = file_permissions_mode else: self.file_permissions_mode = settings.FILE_UPLOAD_PERMISSIONS if directory_permissions_mode is not None: self.directory_permissions_mode = directory_permissions_mode else: self.directory_permissions_mode = settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS
def __init__(self, file_permissions_mode=None, directory_permissions_mode=None): location = os.path.join(settings.BASE_DIR, 'private') base_url = '/private-uploads/' self.base_location = location self.location = abspathu(self.base_location) if base_url is None: base_url = '' elif not base_url.endswith('/'): base_url += '/' self.base_url = base_url self.file_permissions_mode = (file_permissions_mode if file_permissions_mode is not None else settings.FILE_UPLOAD_PERMISSIONS) self.directory_permissions_mode = ( directory_permissions_mode if directory_permissions_mode is not None else settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS)
def __init__(self, location=None, base_url=None, file_permissions_mode=None, directory_permissions_mode=None): if location is None: location = settings.MEDIA_ROOT self.base_location = location self.location = abspathu(self.base_location) if base_url is None: base_url = settings.MEDIA_URL elif not base_url.endswith('/'): base_url += '/' self.base_url = base_url self.file_permissions_mode = ( file_permissions_mode if file_permissions_mode is not None else settings.FILE_UPLOAD_PERMISSIONS ) self.directory_permissions_mode = ( directory_permissions_mode if directory_permissions_mode is not None else settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS )
def form_valid(self, form): with transaction.atomic(): form.instance.created_by = self.request.user form.instance.updated_by = self.request.user name = os.path.splitext(self.request.FILES['document'].name)[0] form.instance.name = name form.instance.item = self.owner self.object = form.save() abs_path = abspathu(settings.MEDIA_ROOT) path = self.object.document.path bucket_path = path[len(abs_path) + 1:] if abs_path in path else path params = {'file': path, 'bucket_path': bucket_path} tasks.upload_file.apply((params, )) return HttpResponse('')
def __init__(self, the_day, location=None, inst='ab', file_permissions_mode=None, directory_permissions_mode=None): if location is None: location = settings.FINANCE_ROOT if inst is not None: location = os.path.join(location, inst) if isinstance(the_day, str): the_day = parser.parse(the_day) elif not isinstance(the_day, (datetime, date)): raise ValueError location = os.path.join(location, the_day.strftime('%Y%m%d')) self.base_location = location self.location = abspathu(self.base_location) self.file_permissions_mode = (None ) self.directory_permissions_mode = (None ) self.name = ''
def __init__(self, the_day, location=None, inst='ab', file_permissions_mode=None, directory_permissions_mode=None): if location is None: location = settings.FINANCE_ROOT if inst is not None: location = os.path.join(location, inst) if isinstance(the_day, str): the_day = parser.parse(the_day) elif not isinstance(the_day, (datetime, date)): raise ValueError location = os.path.join(location, the_day.strftime('%Y%m%d')) self.base_location = location self.location = abspathu(self.base_location) self.file_permissions_mode = (None) self.directory_permissions_mode = (None) self.name = ''
def __init__(self, location=None, base_url=None): """ Initialize a Git repository or open an existing one. @param location: path where to create and open the repository """ if not location: try: location = settings.GIT_STORAGE_ROOT except AttributeError: raise ImproperlyConfigured("GIT_STORAGE_ROOT is required") self.base_location = location self.location = abspathu(self.base_location) if base_url is None: try: base_url = settings.GIT_STORAGE_URL except AttributeError: base_url = None self.base_url = base_url # Reference (head) try: self.reference = settings.GIT_STORAGE_REFERENCE except AttributeError: self.reference = DEFAULT_REFERENCE # Author try: self.author_name, self.author_email = settings.GIT_STORAGE_AUTHOR except AttributeError: self.author_name, self.author_email = DEFAULT_AUTHOR # Committer try: self.committer_name, self.committer_email = settings.GIT_STORAGE_COMMITTER except AttributeError: self.committer_name, self.committer_email = DEFAULT_AUTHOR # Save message try: self.save_message = settings.GIT_STORAGE_SAVE_MESSAGE except AttributeError: self.save_message = DEFAULT_SAVE_MESSAGE # Delete message try: self.delete_message = settings.GIT_STORAGE_DELETE_MESSAGE except AttributeError: self.delete_message = DEFAULT_DELETE_MESSAGE # Create repository if not os.path.exists(location): repository = pygit2.init_repository(self.location, True) # Bare # Initial commit author = utils.make_signature(self.author_name, self.author_email) committer = utils.make_signature(self.committer_name, self.committer_email) tree = repository.TreeBuilder().write() repository.create_commit(self.reference, author, committer, INITIAL_COMMIT_MESSAGE, tree, []) del repository # Open our repository instance self.repository = wrappers.Repository(self.location) assert self.repository.is_bare
def location(self): return abspathu(self.base_location)
def path(self, name): self.location = abspathu(settings.ENHYDRIS_TIMESERIES_DATA_DIR) return super(TimeseriesStorage, self).path(name)
def datafilename(self): directory = abspathu(settings.ENHYDRIS_TIMESERIES_DATA_DIR) filename = "{:010}".format(self.timeseries.id) return os.path.join(directory, filename)
def path(self, name): self.location = abspathu(settings.ENHYDRIS_TIMESERIES_DATA_DIR) return super().path(name)
import errno