Author Topic: Odd request....  (Read 4916 times)

garion911

  • Senior Community Member
  • Posts: 184
  • Hero Points: 13
Odd request....
« on: February 14, 2007, 05:10:51 am »
I have an odd development environment.. I have a situation where I would like to edit my files with Slick, but be saved into 2 locations.. The first location being a local copy of the project, and another remote location, containing the same set of files..

Here's an example:

I edit a file X/Y/Z/oddball.py on my local system.
When I save it, I want a copy saved to X/Y/Z/oddball.py and to myaccount@remoteserver:X/Y/Z/oddball.py

I've tried things with the SFTP in Slick, but it seems that the only way to do it, is to open the file via SFTP.. I'd rather use the project to open my files.

I've also tried using the File options|backup (global nested dir) and using a sshfs mount, but backup only seems to save the first copy of the file when editting. I would like it to save a backup on every save.

Can anyone come up with way to do what i would like? Ideally, it could be configured on a project (or workspace) by project basis. Though I can live without that.

I currently use some really hacked up stuff to achieve it (some homebrew 'watch for file change, then use sftp to send it' stuff..), but would like to use something a little less frail..

Using OSX (sshfs via MacFuse from google).

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: Odd request....
« Reply #1 on: February 14, 2007, 06:52:17 pm »
Actually, this is an interesting request. I'll look into adding this for a future release. Right now, I'm inclined to provide an option on the Tools > Options > File Options > Backup screen. The current capability is very close if you select "Global Nested Directories", except that it writes out the file as it was before you began this editing session.

--Scott

garion911

  • Senior Community Member
  • Posts: 184
  • Hero Points: 13
Re: Odd request....
« Reply #2 on: February 14, 2007, 07:48:15 pm »
Yeah, I like to have an odd environment.. The code runs on a linux box, but I want to have files locally for a graphical svn merge.. Plus my ssh goes over a VPN, so saving is slow if I try to just go straight SFTP, so I prefer to save to local disk... Plus it gives me a built-in backup if the linux box catches fire.

If you could put the second save as a background process, that would be awesome.

What I have now is a mishmash of sftp and a python script hooking into the FSevents stuff on OSX.. I have to remember to turn it off during certain cirumstances, and it can get really confusing..

I even looked (briefly) into filesystem overlays to handle this, but they didnt look like they could.. *sigh*..

I should look into something in FUSE.. There might be some mirroring stuff there that may work..

But ideally, having Slick do it for me would be perfect.

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Odd request....
« Reply #3 on: February 14, 2007, 09:04:39 pm »
Maybe there is already a possibilty to achieve that.
You can use the '_cbsave_' callback, which is invoked right after saving the current buffer.
Example:
Code: [Select]
void _cbsave_garion911()
{
   // optional: activate 'Build' win to see what's going on
   activate_build ();

   _str cmdline="<add your shell command to remote-copy the current buffer in bg>";
   concur_command (cmdline, false, true, false, false);
   
   // optional: switch focus back to edit win to continue working
   cursor_data();
}

Unfortunately the current implementation of 'saveload.e - save_file()' doesn't support args to the callback and it's only called if the current buffer was saved successfully.
IE you only get trigged if you save the current buffer and not for all files when you 'File->Save All'.

To achieve that you could apply this patch to 'saveload.e - save_file()':
Code: [Select]
   ...
   // add new callback to process a file/buffer right after saving
   if (!status) call_list('_postsavefile_',filename,options);

   return(status);
}

and provide this callback instead of '_cbsave_garion911':
Code: [Select]
// called right after Slick saved a file / the current buffer
// requires '_postsavefile_'-callback patch in saveload.e:save_file()
_postsavefile_garion911(_str filename,_str &options)
{
   say ( "_postsavefile_garion911: filename: " filename ");
   // see above
}

Good luck,

HS2

garion911

  • Senior Community Member
  • Posts: 184
  • Hero Points: 13
Re: Odd request....
« Reply #4 on: February 16, 2007, 04:59:11 pm »
I wish to thank hs2 for his suggestions... I followed them pretty closely, and got exactly what i needed to work!

I used his second suggestion, adding a callback that sends my function the filename.. Then i wrote a python script that first checks if the project is one I wish to 'double save', then I copy the file.. Here's the python script I wrote:

Code: [Select]
import sys
import shutil

localdir = "/Users/garion/work/"
remotedir = "/Users/garion/remote-work/"

projects = ['xml-api','pyultraapi','pyultralib','ultraxfr']

fname = sys.argv[1]

if not fname.startswith(localdir):
    sys.exit(0)

project = fname[ len(localdir) : fname.find( '/', len(localdir)) ]

if project not in projects:
    sys.exit(0)

localfile = fname
remotefile = remotedir + fname[len(localdir):]

shutil.copyfile( localfile, remotefile )

Works like a champ!

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: Odd request....
« Reply #5 on: February 16, 2007, 07:08:52 pm »
Congrats garion911 - pretty cool (HP++) !

BTW: You could easily add a Slick-project (<project>.vpj) check in the callback too.
Example:
Code: [Select]
// global and persistent config var (@see vusrdefs.e)
// set/change by using 'set-var def_double_save_projects_re' on cmdline.
_str def_double_save_projects_re = "xml-api|pyultraapi|pyultralib|ultraxfr";

_postsavefile_garion911(_str filename,_str &options)
{
   if ( pos ( strip_filename (_project_name, 'PDE'), def_double_save_projects_re, 1, 'RI' ) )
   {
      message ( "do double save ...");
      ...
      _str cwd=_ProjectGet_WorkingDir (_ProjectHandle (_project_name));

      if ( cwd != '' )
      {
         cwd=absolute (cwd, strip_filename (_project_name,'n'));
         ...
      }
   }
}
   

HS2

garion911

  • Senior Community Member
  • Posts: 184
  • Hero Points: 13
Re: Odd request....
« Reply #6 on: February 16, 2007, 07:42:30 pm »
Yeah, I figured I could do the same thing in Slick-C, but I'm already behind schedule on projects, and I would have the Slick-C learning curve.. Stick with what I know :)

One advantage to the python one is that I can use it with other apps, or even standalone..  Not so sure about using slick to do it with other utils..