-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure for writing to pluggable galaxy file sources.
- Loading branch information
Showing
14 changed files
with
305 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import Backbone from "backbone"; | ||
import { filesDialog } from "utils/data"; | ||
import _l from "utils/localization"; | ||
import Ui from "mvc/ui/ui-misc"; | ||
|
||
var View = Backbone.View.extend({ | ||
initialize: function (options) { | ||
this.model = new Backbone.Model(); | ||
this.target = options.target; | ||
|
||
// create insert edit button | ||
this.browse_button = new Ui.Button({ | ||
title: _l("Select"), | ||
icon: "fa fa-edit", | ||
tooltip: _l("Select URI"), | ||
onclick: () => { | ||
filesDialog( | ||
(uri) => { | ||
this._handleRemoteFilesUri(uri); | ||
}, | ||
{ mode: "directory" } | ||
); | ||
}, | ||
}); | ||
|
||
// add change event. fires on trigger | ||
this.on("change", () => { | ||
if (options.onchange) { | ||
options.onchange(this.value()); | ||
} | ||
}); | ||
|
||
// create elements | ||
this.setElement(this._template(options)); | ||
this.$text = this.$(".ui-uri-preview"); | ||
this.$(".ui-file-select-button").append(this.browse_button.$el); | ||
this.listenTo(this.model, "change", this.render, this); | ||
this.render(); | ||
}, | ||
|
||
_handleRemoteFilesUri: function (uri) { | ||
this._setValue(uri); | ||
}, | ||
|
||
render: function () { | ||
const value = this._value; | ||
if (value) { | ||
if (value.url !== this.$text.text()) { | ||
this.$text.text(value.url); | ||
} | ||
} else { | ||
this.$text.text("select..."); | ||
} | ||
}, | ||
|
||
/** Main Template */ | ||
_template: function (options) { | ||
return ` | ||
<div class="ui-rules-edit clearfix"> | ||
<span class="ui-uri-preview" /> | ||
<span class="ui-file-select-button float-left" /> | ||
</div> | ||
`; | ||
}, | ||
|
||
/** Return/Set current value */ | ||
value: function (new_value) { | ||
if (new_value !== undefined) { | ||
this._setValue(new_value); | ||
} else { | ||
return this._getValue(); | ||
} | ||
}, | ||
|
||
/** Update input element options */ | ||
update: function (input_def) { | ||
this.target = input_def.target; | ||
}, | ||
|
||
/** Returns current value */ | ||
_getValue: function () { | ||
return this._value.url; | ||
}, | ||
|
||
/** Sets current value */ | ||
_setValue: function (new_value) { | ||
if (new_value) { | ||
if (typeof new_value == "string") { | ||
new_value = JSON.parse(new_value); | ||
} | ||
this._value = new_value; | ||
this.model.trigger("error", null); | ||
this.model.trigger("change"); | ||
} | ||
}, | ||
}); | ||
|
||
export default { | ||
View: View, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<tool id="directory_uri" name="directory_uri" version="1.0.0"> | ||
<command><![CDATA[ | ||
python '$__tool_directory__/directory_uri_copy_to.py' | ||
--file_sources '$file_sources' | ||
--directory_uri '$d_uri' | ||
]]></command> | ||
<inputs> | ||
<param type="directory_uri" name="d_uri" label="Directory URI" /> | ||
</inputs> | ||
<outputs> | ||
</outputs> | ||
<configfiles> | ||
<file_sources name="file_sources" /> | ||
</configfiles> | ||
<tests> | ||
</tests> | ||
</tool> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import argparse | ||
import json | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
from galaxy.files import ConfiguredFileSources | ||
|
||
|
||
def get_file_sources(file_sources_path): | ||
assert os.path.exists(file_sources_path), "file sources path [%s] does not exist" % file_sources_path | ||
with open(file_sources_path, "r") as f: | ||
with open("/Users/john/workspace/galaxy/cowdog", "w") as g: | ||
g.write(f.read()) | ||
with open(file_sources_path, "r") as f: | ||
file_sources_as_dict = json.load(f) | ||
file_sources = ConfiguredFileSources.from_dict(file_sources_as_dict) | ||
return file_sources | ||
|
||
|
||
def main(argv=None): | ||
if argv is None: | ||
argv = sys.argv[1:] | ||
|
||
args = _parser().parse_args(argv) | ||
file_sources = get_file_sources(args.file_sources) | ||
directory_uri = args.directory_uri | ||
if directory_uri.endswith("/"): | ||
target_uri = directory_uri + "helloworld" | ||
else: | ||
target_uri = directory_uri + "/helloworld" | ||
file_source_path = file_sources.get_file_source_path(target_uri) | ||
file_source = file_source_path.file_source | ||
fd, temp_name = tempfile.mkstemp() | ||
with open(fd, 'w') as f: | ||
f.write('hello world!\n') | ||
file_source.write_from(file_source_path.path, temp_name) | ||
|
||
|
||
def _parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--directory_uri', type=str, | ||
help='directory target URI') | ||
parser.add_argument('--file_sources', type=str, help='file sources json') | ||
return parser | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.