免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1987 | 回复: 1
打印 上一主题 下一主题

PHP写UltraEdit插件脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-31 16:29 |只看该作者 |倒序浏览
PHP写UltraEdit插件脚本






需求:

1 svn上的代码在本地(编辑器UltraEdit)有一套,在开发机(centos)上有一套,需要本地的代码修改以后上传到开发机上

2 不直接在开发机上修改和使用,原因是有多个人都使用同一个开发机,为了保留本地备份



思路:

1 写一个脚本作为UltraEdit的插件,使得代码修改后按下制定按键就能直接将代码本地保存后上传到centos上

2 本地是windows,远程是linux,文件上传工具可以使用pscp.exe,脚本语言使用PHP或者Python

3 本地必须安装PHP,不需要安装数据库和apache

4 在PHP中起一个进程调用pscp.exe, 解析路径等逻辑放在php中



步骤:

1 UltaEdit中在工具配置中设定好脚本

php  "C:\Users\nickyjf\Desktop\mesh\Tools\syncFile\sync142.php" %p%n%e

后面的%p%n%e是当前编辑文件的绝对路径,作为参数传入synv142.php中





2 sync142.php代码



View Code
  1. <?php
  2. //插件,将windwos文件同步到linux上
  3. //php "rsync142.php" %p%n%e

  4. //valid    argv
  5. //testCode
  6. /*
  7. $argv = array(
  8.     "rsync142.php",
  9.     "E:\\SVN\\test\\www\\include\\ggg\\test\\DTest.php",
  10. );
  11. */

  12. if(count($argv)    == 2)
  13. {
  14.     $sFilePath = $argv[1];
  15.    
  16.     $sServerName = "192.168.10.142";
  17.     $sServerUserName = "name";
  18.     $sServerPassword = "password";
  19.    
  20.     $sServerPath = sGetServerPath($sFilePath);
  21.     $realPath = sprintf("%s@%s:/%s", $sServerUserName, $sServerName, $sServerPath);
  22.    
  23.     try
  24.     {
  25.         $cmd = sprintf("pscp.exe -pw %s %s %s", $sServerPassword, $sFilePath, $realPath);
  26.         echo $cmd."\n";
  27.         
  28.         system($cmd);
  29.     }
  30.     catch(Exception $e)
  31.     {
  32.         print_r($e);exit;
  33.     }
  34. }

  35. function sGetServerPath($sWindowsPath)
  36. {
  37.     $ret = "";
  38.     $paths = explode("\\", $sWindowsPath);
  39.     if($startKey = array_search("www", $paths))
  40.     {
  41.         $ret = "test/";
  42.         for($i=$startKey+1;    $i<count($paths); $i++)
  43.         {
  44.             $ret .=    $paths[$i] . "/";
  45.         }
  46.         $ret = trim($ret, "/");
  47.     }
  48.     return $ret;
  49. }
  50. ?>
复制代码
3 将pscp.exe放在sync142同级目录下


4 将按键Ctrl + 1 映射到这个脚本
于是在编写程序的时候只要按下Ctrl + 1就可以将当前脚本替换远程脚本

论坛徽章:
0
2 [报告]
发表于 2011-12-31 16:45 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP