eppye-bots / bots

Automatically exported from code.google.com/p/bots
66 stars 126 forks source link

File rename after outcommunication (using *.tmp filenames) #249

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
To avoid that files are read before writing is done.
especially useful for ftp (and variants).
Files is first written with a tmp-filename, and renamed afterwards.

Original issue reported on code.google.com by hjebb...@gmail.com on 6 Sep 2013 at 5:13

GoogleCodeExporter commented 9 years ago
Must also support tmp directory. I have several instances where receiver picks 
up all files in monitored directory, even *.tmp

Original comment by mjg1964 on 7 Sep 2013 at 2:59

GoogleCodeExporter commented 9 years ago
currently I have done this with subclassing ftp disconnect in 
communicationscript based on filename or folder name ending with 'tmp'.

        # rename files to remove .tmp extensions
        if self.channeldict['filename'].endswith('.tmp'):
            try:
                for f in self.session.nlst('*.tmp'):
                    self.session.rename(f,f[:-4])
            except:
                pass

        # rename files from tmp subdirectory to parent directory
        # assumes all files have an extension, sub-dirs do not
        if self.channeldict['path'].endswith('/tmp'):
            try:
                for f in self.session.nlst('*.*'): # files only!
                    self.session.rename(f,'../%s' %f)
            except:
                pass

Original comment by mjg1964 on 22 Dec 2013 at 12:08

GoogleCodeExporter commented 9 years ago
yes!
I am looking on how to implement this 'as upward compatible a possible.
henk-jan

Original comment by hjebb...@gmail.com on 22 Dec 2013 at 7:23

GoogleCodeExporter commented 9 years ago
hard to make this general. especially for directories.
could use a extra attribute 'append as tmp indicator'; but this only works for 
the file part. Think this would cover most use cases?

Original comment by hjebb...@gmail.com on 28 Dec 2013 at 3:30

GoogleCodeExporter commented 9 years ago

Original comment by hjebb...@gmail.com on 29 Dec 2013 at 11:00

GoogleCodeExporter commented 9 years ago
change is in repository now.
works like this:
- added new field in channel: 'tmp part of file name'
- bots writes the file the usual way (using path and filename).
- generate definitive filename by removing (last occurence of) 'tmp part of 
file name' from filename. 
- when file is written, bots renames the file to definitive filename.
example:
path= '/dir1', filename= '*.edi.tmp'
file is written as '/dir1/123.edi.tmp'
file is renamed to  '/dir1/123.edi'

For tmp directories: this works for file system (bots adds path en filename, 
than deletes the tmp part from this complete path.
for ftp: this works differently, as bots does a cwd and than writes the 
filename. Using path information in writing files to ftp will run into 
differences of ftp servers. 

Original comment by hjebb...@gmail.com on 14 Jan 2014 at 12:24

GoogleCodeExporter commented 9 years ago

Original comment by hjebb...@gmail.com on 14 Jan 2014 at 1:11

GoogleCodeExporter commented 9 years ago

Original comment by hjebb...@gmail.com on 10 Sep 2014 at 2:42