Update api and filesystem modules to new os_specifics

renames
This commit is contained in:
Roberto Rosario
2011-11-30 09:33:32 -04:00
parent a646997ab8
commit 1e22d1099e
2 changed files with 13 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ from document_indexing.filesystem import fs_create_index_directory, \
fs_create_document_link, fs_delete_document_link, \ fs_create_document_link, fs_delete_document_link, \
fs_delete_index_directory, fs_delete_directory_recusive fs_delete_index_directory, fs_delete_directory_recusive
from document_indexing.conf.settings import SLUGIFY_PATHS from document_indexing.conf.settings import SLUGIFY_PATHS
from document_indexing.os_agnostic import assemble_document_filename from document_indexing.os_specifics import assemble_suffixed_filename
if SLUGIFY_PATHS == False: if SLUGIFY_PATHS == False:
# Do not slugify path or filenames and extensions # Do not slugify path or filenames and extensions
@@ -131,10 +131,10 @@ def find_lowest_available_suffix(index_instance, document):
index_instance_documents = DocumentRenameCount.objects.filter(index_instance=index_instance)#.filter(document__file_extension=document.file_extension) index_instance_documents = DocumentRenameCount.objects.filter(index_instance=index_instance)#.filter(document__file_extension=document.file_extension)
files_list = [] files_list = []
for index_instance_document in index_instance_documents: for index_instance_document in index_instance_documents:
files_list.append(assemble_document_filename(index_instance_document.document, index_instance_document.suffix)) files_list.append(assemble_suffixed_filename(index_instance_document.document.file.name, index_instance_document.suffix))
for suffix in xrange(MAX_SUFFIX_COUNT): for suffix in xrange(MAX_SUFFIX_COUNT):
if assemble_document_filename(document, suffix) not in files_list: if assemble_suffixed_filename(document.file.name, suffix) not in files_list:
return suffix return suffix
raise MaxSuffixCountReached(ugettext(u'Maximum suffix (%s) count reached.') % MAX_SUFFIX_COUNT) raise MaxSuffixCountReached(ugettext(u'Maximum suffix (%s) count reached.') % MAX_SUFFIX_COUNT)

View File

@@ -3,7 +3,8 @@ import os
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from document_indexing.os_agnostic import assemble_document_filename from document_indexing.os_specifics import (assemble_suffixed_filename,
assemble_path_from_list)
from document_indexing.conf.settings import FILESERVING_ENABLE from document_indexing.conf.settings import FILESERVING_ENABLE
from document_indexing.conf.settings import FILESERVING_PATH from document_indexing.conf.settings import FILESERVING_PATH
@@ -19,12 +20,12 @@ def get_instance_path(index_instance):
names.append(index_instance.value) names.append(index_instance.value)
return os.sep.join(names) return assemble_path_from_list(names)
def fs_create_index_directory(index_instance): def fs_create_index_directory(index_instance):
if FILESERVING_ENABLE: if FILESERVING_ENABLE:
target_directory = os.path.join(FILESERVING_PATH, get_instance_path(index_instance)) target_directory = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance)])
try: try:
os.mkdir(target_directory) os.mkdir(target_directory)
except OSError, exc: except OSError, exc:
@@ -36,8 +37,9 @@ def fs_create_index_directory(index_instance):
def fs_create_document_link(index_instance, document, suffix=0): def fs_create_document_link(index_instance, document, suffix=0):
if FILESERVING_ENABLE: if FILESERVING_ENABLE:
filename = assemble_document_filename(document.file_filename, suffix) filename = assemble_suffixed_filename(document.file.name, suffix)
filepath = os.path.join(FILESERVING_PATH, get_instance_path(index_instance), filename) filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename])
try: try:
os.symlink(document.file.path, filepath) os.symlink(document.file.path, filepath)
except OSError, exc: except OSError, exc:
@@ -55,8 +57,8 @@ def fs_create_document_link(index_instance, document, suffix=0):
def fs_delete_document_link(index_instance, document, suffix=0): def fs_delete_document_link(index_instance, document, suffix=0):
if FILESERVING_ENABLE: if FILESERVING_ENABLE:
filename = assemble_document_filename(document.file_filename, suffix) filename = assemble_suffixed_filename(document.file.name, suffix)
filepath = os.path.join(FILESERVING_PATH, get_instance_path(index_instance), filename) filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename])
try: try:
os.unlink(filepath) os.unlink(filepath)
@@ -68,7 +70,7 @@ def fs_delete_document_link(index_instance, document, suffix=0):
def fs_delete_index_directory(index_instance): def fs_delete_index_directory(index_instance):
if FILESERVING_ENABLE: if FILESERVING_ENABLE:
target_directory = os.path.join(FILESERVING_PATH, get_instance_path(index_instance)) target_directory = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance)])
try: try:
os.removedirs(target_directory) os.removedirs(target_directory)
except OSError, exc: except OSError, exc: