diff -u -r LocalFS.org/LocalFS.py LocalFS/LocalFS.py --- LocalFS.org/LocalFS.py 2002-08-22 09:16:47.000000000 +0900 +++ LocalFS/LocalFS.py 2002-10-04 00:53:24.000000000 +0900 @@ -37,14 +37,29 @@ # (http://www.zope.org/)." # ############################################################################## +# Write By Kiyoharu Ueno +# No.1 2002/07/10 Chage LocalFS Products (for LocalFS-0.10.1) +# 1. LocalDirectory.manege_upload +# 2. LocalDirectory._write_file +# +# Write By Fukuoka Zope User Group (http://fzug.com/) +# 2002/09/09 For LocalFS-1.0.0(LocalFS-1.0.0-000jp) +# 2002/09/13 For LocalFS-1.0.0(LocalFS-1.0.0-001jp-win) +# +############################################################################## """Local File System product""" -__version__='$Revision: 1.1 $'[11:-2] +__version__='$Revision: 1.11 $'[11:-2] +#kconvYes=0 +#try: +# import kconv +# kconvYes=1 +#except ImportError: pass import sys, os, string, re, stat, urllib, glob, errno, time, tempfile import App, Globals, Acquisition, Persistence, OFS -import AccessControl, re +import AccessControl, re, ts_regex, base64 from App.Extensions import getObject from webdav.NullResource import NullResource from ZPublisher.HTTPResponse import HTTPResponse @@ -66,7 +81,7 @@ import re unc_expr = re.compile(r'(\\\\[^\\]+\\[^\\]+)(.*)') -_test_read = 1024 * 8 +_test_read = 1024 _unknown = '(unknown)' ############################################################################ @@ -84,6 +99,51 @@ # shouldn't have and change the type back to 'text/plain'. This # also happens in _set_content_type. ############################################################################ +# 2002/09/09 write. + +def filetoeuc(line): + ret = line + try: + import kconv + ret = kconv.Kconv(kconv.EUC,kconv.AUTO,kconv.ZENKAKU,kconv.TABLE).convert(line) + except: + try: + import pykf + ret = pykf.toeuc(line) + except: + try: + import euc_jp + euc=euc_jp.Codec + ret = euc.encode(line) + except: + pass + return ret + +def filetosjis(line): + ret = line + try: + import kconv + ret = kconv.Kconv(kconv.SJIS,kconv.AUTO,kconv.ZENKAKU,kconv.TABLE).convert(line) + except: + try: + import pykf + ret = pykf.tosjis(line) + except: + try: + import sjis + sjis=shift_jis.Codec + ret = sjis.encode(line) + except: + pass + return ret + +def filetoencode(line): + if (_iswin32): + if line[len(line)-1] == '\\': + line = line+'.tmp' + return filetosjis(line) + else: + return filetoeuc(line) def _get_content_type(ext, _type_map): try: return _type_map[ext] @@ -401,7 +461,8 @@ if id == os.curdir or id == os.pardir or id[0] == '_': return 0 return 1 -bad_id=re.compile('[^a-zA-Z0-9-_~,. ]').search #TS +#bad_id=re.compile('[^a-zA-Z0-9-_~,. ]').search #TS +#badjp_id=ts_regex.compile('[^a-zA-Z0-9-_~,. ]').search #TS def absattr(attr): if callable(attr): return attr() @@ -471,6 +532,10 @@ except 'NotFound': raise AttributeError, attr def _getpath(self, id): +# if kconvYes: +# toId = kconv.Kconv(kconv.EUC,kconv.AUTO,kconv.ZENKAKU,kconv.TABLE) +# toId = kconv.Kconv() +# id = toId.convert(id) return os.path.join(self.basepath, id) def _getfileob(self, id, spec=None): @@ -499,7 +564,7 @@ for patt in spec: names = glob.glob(patt) for id in names: - if id[-1] == os.sep: id = id[:-1] + if not (_iswin32) and id[-1] == os.sep: id = id[:-1] if (id not in l): l.append(id) ids = l @@ -554,9 +619,9 @@ # only check that the id string contains no illegal chars. if not id: raise 'Bad Request', 'No id was specified' - if bad_id(id): - raise 'Bad Request', ( - 'The id %s contains characters illegal in filenames.' % id) +# if bad_id(id) and badjp_id(id): +# raise 'Bad Request', ( +# 'The id %s contains characters illegal in filenames.' % id) if id[0]=='_': raise 'Bad Request', ( 'The id %s is invalid - it begins with an underscore.' % id) if not allow_dup: @@ -624,20 +689,38 @@ def _verifyObjectPaste(self, ob, REQUEST): pass - def _write_file(self, file, path): + def _write_file(self, rfile, chkbtn, ftype, path): try: - if type(file) is StringType: - outfile=open(path,'wb') - outfile.write(file) - outfile.close() + if ftype == 0: + if chkbtn == 'a': + outfile = open(path, 'ab') + rfile.seek(0,os.path.getsize(path)) + else: + outfile = open(path, 'wb') else: - blocksize=8*1024 - outfile=open(path,'wb') - data=file.read(blocksize) - while data: - outfile.write(data) - data=file.read(blocksize) - outfile.close() + if chkbtn == 'a': + outfile = open(path, 'a') + rfile.seek(0,os.path.getsize(path)) + else: + outfile = open(path, 'w') + data = rfile.read(_test_read) + while data: + outfile.write(data) + data = rfile.read(_test_read) + outfile.close() +# try: +# if type(file) is StringType: +# outfile=open(path,'wb') +# outfile.write(file) +# outfile.close() +# else: +# blocksize=8 * 1024 +# outfile=open(path,'wb') +# data=file.read(blocksize) +# while data: +# outfile.write(data) +# data=file.read(blocksize) +# outfile.close() except EnvironmentError, err: if (err[0] == errno.EACCES): raise 'Forbidden', HTTPResponse()._error_html( @@ -671,13 +754,25 @@ message='The directory has been created.', action=action) - def manage_upload(self, file, id='', action='manage_workspace', REQUEST=None): + def manage_upload(self, file, frb, id='', action='manage_workspace', REQUEST=None): """Upload a file to the local file system. The 'file' parameter is a FileUpload instance representing the uploaded file.""" + if hasattr(file,'filename'): filename=file.filename else: filename=file.name + + chkbtn=frb + mes='

ファイル名を選択して下さい。

' + if filename=='': + raise ValueError, "ファイル名が必要です。" + #else: + # filename = filetoencode(filename) + # if kconvYes: + # toEUC=kconv.Kconv() + # filename = toEUC.convert(filename) + if not id: # Try to determine the filename without any path. # First check for a UNIX full path. There will be no UNIX path @@ -689,7 +784,12 @@ # relative UNIX path which happens to have backslashes in it. # Lets hope this never happens, anyway. ;) elif '\\' in filename: - id=filename[string.rfind(filename,'\\')+1:] + if (_iswin32): + filename = filetoeuc(filename) + id = filename[string.rfind(filename,'\\')+1:] + id = filetosjis(id) + else: + id=filename[string.rfind(filename,'\\')+1:] # Not sure if we'll ever get a Mac path, but here goes... elif ':' in filename: id=filename[string.rfind(filename,':')+1:] @@ -697,22 +797,49 @@ # that for the id. else: id=filename - + id = filetoencode(id) try: self._checkId(id,1) except: raise 'Upload Error', MessageDialog( title='Invalid Id', message=sys.exc_value, - action ='manage_main') + action ='manage_main') path = self._getpath(id) - if os.path.exists(path): self.manage_overwrite(file, path, REQUEST) - else: self._write_file(file, path) - + data = file.read(_test_read) + if (find_binary(data) >= 0): + ftype=0 + else: + ftype=1 + """ 読み込みbuff先頭へ """ + file.seek(0,0) + if os.path.exists(path): + if chkbtn=='s': + mes='

同名ファイルがあります。

処理を中止しました。

' + + elif chkbtn=='a': + #rbuff=file.tell() + file.seek(0,2) + rbuff= file.tell() + file.seek(0,0) + wbuff=os.path.getsize(path) + if rbuff > wbuff: + self._write_file(file, chkbtn, ftype, path) + mes='

(OK WriteBuff:%sbyte)

追加送信完了

' % (wbuff) + else: + mes='

(Not ReadBuff:%sbyte)

処理はすでに完了しています。

' % (rbuff) + + else: + self.manage_overwrite(file, chkbtn, ftype, path, REQUEST) + mes='

(OK Writen)

上書きが完了しました.

' + else: + self._write_file(file, chkbtn, ftype, path) + mes='

(OK Writen)

送信が完了しました。

' + if REQUEST: return MessageDialog( - title='Success!', - message='Your file has been uploaded.', + title='アップロード結果', + message='%s' % (mes), action=action) - def manage_overwrite(self, file, path, REQUEST=None): + def manage_overwrite(self, rfile, chkbtn, ftype, path, REQUEST=None): """Overwrite a local file.""" if REQUEST is None and hasattr(self, 'aq_acquire'): try: REQUEST=self.aq_acquire('REQUEST') @@ -723,7 +850,7 @@ raise 'Unauthorized', HTTPResponse()._error_html( 'Unauthorized', "Sorry, you are not authorized to overwrite files.

") - self._write_file(file, path) + self._write_file(rfile, chkbtn, ftype, path) def manage_renameObject(self, id, new_id, REQUEST=None): """Rename a file or subdirectory.""" @@ -1043,6 +1170,8 @@ self.mtime = self._getTime() self.display_size = self._getDisplaySize() self.display_mtime = self._getDisplayTime() + self.display_jtime = self._getDisplayJTime() + self.display_jmtime = self._getDisplayJmTime() def getObject(self): """Return a Zope object representing this local file.""" @@ -1131,6 +1260,26 @@ if t is None: return _unknown return '%s %s' % (t.Time(), t.Date()) + def _getDisplayJTime(self): + """Return the last modified time of a file or directory formatted + for display.""" + t = self.mtime + wk_j=['日','月','火','水','木','金','土'] + if t is None: return _unknown + return '%s%s%s%s%s%s%s %s' % (t.year(), '年', t.mm(), '月',t.dd(), '日', '('+wk_j[t.dow()]+')', t.TimeMinutes()) + + + def _getDisplayJmTime(self): + """Return the last modified time of a file or directory formatted + for display.""" + t = self.mtime + wk_j=['日','月','火','水','木','金','土'] + if t is None: return _unknown + return '%s%s%s%s%s%s%s %s' % (t.year(), '年', t.mm(), '月',t.dd(), '日', '('+wk_j[t.dow()]+')', t.Time()) + + + + class FileMoniker: """A file moniker is a reference to an object in the file system.""" diff -u -r LocalFS.org/__init__.py LocalFS/__init__.py --- LocalFS.org/__init__.py 2002-08-22 09:16:47.000000000 +0900 +++ LocalFS/__init__.py 2002-08-28 02:07:25.000000000 +0900 @@ -39,7 +39,7 @@ ############################################################################## __doc__="""Local File System product initialization""" -__version__='$Revision: 1.1 $'[11:-2] +__version__='$Revision: 1.1.1.1 $'[11:-2] import os, LocalFS from Globals import ImageFile diff -u -r LocalFS.org/dtml/methodAdd.dtml LocalFS/dtml/methodAdd.dtml --- LocalFS.org/dtml/methodAdd.dtml 2002-08-22 09:16:47.000000000 +0900 +++ LocalFS/dtml/methodAdd.dtml 2002-08-28 02:13:41.000000000 +0900 @@ -8,45 +8,25 @@ -

Local File System objects allow you to serve files from -either the local file system or a remote network share as if they were regular -Zope documents.

+

+ローカル・ファイル・システム・オブジェクトは、あたかもそれらが通常のZopeドキュメントかのように、あなたがローカルのファイル・システム、あるいは遠隔のネットワーク・シェアのいずれかからのファイルを操作することを可能にします。

-This works by mapping a directory (called the 'base path') on the Zope server -machine to a folder-like object in Zope. All of the subdirectories and files -under this path are mapped to Zope objects by reading the contents of the file -from the file system each time the object is requested. (For many operations -this is optimized to speed up performance.)

+Zopeの中のフォルダ状のオブジェクトに、Zopeサーバマシンのディレクトリ(「base path」と呼ぶ)をマッピングする。このパスの下のサブディレクトリおよびファイルはすべて、オブジェクトが要求されるごとに、ファイル・システムからファイルの内容を読むことにより、Zopeオブジェクトにマッピングされます。(多くのオペレーションにおいて、これが速度の向上に最適化されます。)

-The Zope process must have permissions at minimum to read from the specified -directory, or to write to the directory to enable file uploads. All uploaded -files are initially owned by the same user as the Zope process. -

+Zopeプロセスが、指定されたディレクトリから読むか、あるいはアップロードを可能にするディレクトリへの書き込み可能な許可を行っている必要があります。アップロードされたファイルはすべて、Zopeプロセスと同じユーザによって最初に所有されます。

-

Specify remote shares using the UNC notation: -\\server\share\path. You may also need to enter a username and a password. -Note: When run as a service, Zope by default runs under -the System account, which does not have the permissions to map network -drives. You must specify a username with sufficient privileges to -use network shares unless you run Zope under a different account.

+

UNCの記法を使用して、リモート共有を指定してください。(\\server\share\path)さらに、ユーザー名およびパスワードを入力する必要があるかもしれません。注:サービスとして実行された時、デフォルトのZopeは、システム・アカウント(それはネットワーク・ドライブをマッピングする許可を行っていない)の下で走ります。もし異なるアカウントの下のZopeを実行しなければネットワーク共有を使用する十分な特権を備えたユーザー名を指定しなければなりません。

-

Local File System objects allow you to serve files from -the local file system as if they were regular Zope documents.

+

ローカル・ファイル・システム・オブジェクトは、あたかもそれらが通常のZopeドキュメントかのように、あなたがローカルのファイル・システム、あるいは遠隔のネットワーク・シェアのいずれかからのファイルを操作することを可能にします。

-This works by mapping a directory (called the 'base path') on the Zope server -machine to a folder-like object in Zope. All of the subdirectories and files -under this path are mapped to Zope objects by reading the contents of the file -from the file system each time the object is requested. (For many operations -this is optimized to speed up performance.)

+Zopeの中のフォルダ状のオブジェクトにZopeサーバマシンのディレクトリ(「base path」と呼ぶ)をマッピングする。このパスの下のサブディレクトリおよびファイルはすべて、オブジェクトが要求されるごとに、ファイル・システムからファイルの内容を読むことにより、Zopeオブジェクトにマッピングされます。(多くのオペレーションにおいて、これが速度の向上に最適化されます。)

-The Zope process must have permissions at minimum to read from the specified -directory, or to write to the directory to enable file uploads. All uploaded -files are initially owned by the same user as the Zope process. +Zopeプロセスが、指定されたディレクトリから読むか、あるいはアップロードを可能にするディレクトリへの書き込み可能な許可を行っている必要があります。アップロードされたファイルはすべて、Zopeプロセスと同じユーザによって最初に所有されます。

@@ -65,7 +45,7 @@
- Title + タイトル(Title)
@@ -75,7 +55,7 @@
- Base Path + 元パス(Base Path)
@@ -86,7 +66,7 @@
- Username + ユーザ名(Username)
@@ -96,7 +76,7 @@
- Password + パスワード(Password)
@@ -108,7 +88,7 @@
- + diff -u -r LocalFS.org/dtml/methodBrowse.dtml LocalFS/dtml/methodBrowse.dtml --- LocalFS.org/dtml/methodBrowse.dtml 2002-08-22 09:16:47.000000000 +0900 +++ LocalFS/dtml/methodBrowse.dtml 2002-08-28 02:13:41.000000000 +0900 @@ -1,18 +1,18 @@ -

Directory listing of

+

」のフォルダ一覧

- - - - + + + + - + @@ -21,15 +21,17 @@ - +
 NameLast Modified Size Typeファイル名最終更新 サイズ mimeタイプ
Parent Directory上位フォルダ      
>      
-

Upload a file +

ファイル追加 +


+日本語ファイル名も可能です。受信時に文字化けするブラウザーをお使いの場合は、保存画面で入力が必要です。 diff -u -r LocalFS.org/dtml/methodEdit.dtml LocalFS/dtml/methodEdit.dtml --- LocalFS.org/dtml/methodEdit.dtml 2002-08-22 09:16:47.000000000 +0900 +++ LocalFS/dtml/methodEdit.dtml 2002-08-28 02:13:41.000000000 +0900 @@ -8,7 +8,7 @@

- Title + タイトル
@@ -18,7 +18,7 @@
- Base Path + 元パス
@@ -29,7 +29,7 @@
- Username + ユーザー名
@@ -39,7 +39,7 @@
- Password + パスワード
@@ -50,7 +50,7 @@
- Default Document + 標準文書
@@ -60,7 +60,7 @@
- Display in Tree View + ツリー表示
@@ -74,7 +74,7 @@
- Include Objects in Catalog + カタログへの包含
@@ -88,7 +88,7 @@
- Type Map + mimeタイプ設定
@@ -98,7 +98,7 @@
- Icon Map + アイコン設定
diff -u -r LocalFS.org/dtml/methodUpload.dtml LocalFS/dtml/methodUpload.dtml --- LocalFS.org/dtml/methodUpload.dtml 2002-08-22 09:16:47.000000000 +0900 +++ LocalFS/dtml/methodUpload.dtml 2002-09-03 23:27:32.000000000 +0900 @@ -2,50 +2,56 @@

-You may upload a file using the form below. -Choose an existing file from your local computer by clicking the -Browse button. - + ファイル送信は下のフォームで +「参照」ボタンをクリック、あなたの手元のコンピュータからファイルを選択します。

- - + + + + + +
- File + 1. ファイル名
- +
-
- -
+
2. すでにファイルが存在する場合:
+
+ + + +
+
3. 「送信」ボタンクリック
+
+

-You can also create new directories relative to the base path of the file -system object using the form below. + 下記のフォームに新規フォルダ名を入力すると、現在の階層下にフォルダが作成されます。

-
- Path + フォルダ名
- + - +