代码分发的良好解决方案

时间:2016-03-03 14:23:25

标签: matlab software-distribution

我在创建需要以纯文本形式分发的程序特定代码(针对多个不同程序)的情况。截至目前和中期,代码仅由我编辑,但许多人使用,他们使用Windows并且是非开发人员。

我想保留一个"存储库"每台计算机都自动进入,因此我可以对代码进行修改,并且可以直接使用它(解决方案会显示在本地的程序特定文件夹中(想想MatLab或其他科学脚本软件)。

毋庸置疑,像git这样的东西会被夸大其辞,而且对他们来说也是一团糟。但是,版本控制和有意识的更新是一个理想的功能。

我能想到的快速而肮脏的解决方案是共享一个Dropbox文件夹,并创建一个将该文件夹复制到其本地程序特定文件夹的Windows自动化任务。

此解决方案中是否存在任何陷阱?你能推荐其他系统吗?

1 个答案:

答案 0 :(得分:5)

Github(或任何git主机)并不像您想象的那样过度,因为您可以依赖web API而不是要求所有用户在本地计算机上安装git。查询此Web API的功能在大多数语言中都可用,因为您只需要能够发出HTTP请求并处理JSON响应。

以下是MATLAB中一个非常简单的更新程序的示例,该更新程序依赖于Github的release feature。 (这可以很容易地修改以与master)进行比较

function yourProgram(doUpdate)
    if exist('doUpdate', 'var') && doUpdate
        update();
    end

    % Do the actual work
end

function update()
    disp('Checking for update')

    % Information about this project
    thisVersion = 'v1.0';
    gitproject = 'cladelpino/project';

    root = ['https://api.github.com/repos/', gitproject];

    % Get the latest release from github
    release = webread([root, '/releases/latest']);

    if ~strcmp(release.tag_name, thisVersion)
        disp('New Version Found')

        % Get the current filename
        thisfile = [mfilename, '.m'];

        url = [root, '/contents/', thisfile];
        fileinfo = webread(url, 'ref', release.tag_name);

        % Download the new version to the current file
        websave(mfilename('fullpath'), fileinfo.download_url);
        disp('New Version downloaded')
    else
        disp('Everything is up to date!');
    end
end

此示例假定您仅更新此单个文件。必须进行修改才能处理整个项目,但考虑到这个例子,它是相当简单的。

相关问题