Skip to content

Commit 2690227

Browse files
Merge pull request #68 from eywalker/master
Make dj.new invoke dj.createSchema if package is missing
2 parents 823675e + 93b7363 commit 2690227

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

+dj/createSchema.m

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
function newSchema
1+
function createSchema(package)
2+
% DJ.CREATESCHEMA - interactively create a new DataJoint schema
3+
%
4+
% INPUT:
5+
% (optional) package - name of the package to be associated with the
6+
% schema
7+
28

39
dbname = input('Enter database name >> ','s');
410

@@ -18,7 +24,15 @@
1824
disp 'database created'
1925
end
2026

21-
folder = uigetdir('./','Select of create package folder');
27+
if nargin < 1
28+
folder = uigetdir('./','Select a package folder');
29+
else
30+
folder = uigetdir('./', sprintf('Select folder to create package %s in', ['+', package]));
31+
if folder
32+
folder = fullfile(folder, ['+', package]);
33+
mkdir(folder)
34+
end
35+
end
2236

2337
if ~folder
2438
disp 'No package selected. Cancelled.'

+dj/new.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ function new(className)
1515

1616
schemaFunction = [className(1:p-1) '.getSchema'];
1717
if isempty(which(schemaFunction))
18-
throwAsCaller(MException('DataJoint:makeClass', 'Cannot find %s', schemaFunction))
18+
fprintf('Package %s is missing. Calling dj.createSchema...\n', className(1:p-1))
19+
% this wouldn't work well if nested package is given
20+
dj.createSchema(className(1:p-1))
21+
if isempty(which(schemaFunction))
22+
throwAsCaller(MException('DataJoint:makeClass', 'Cannot find %s', schemaFunction))
23+
end
1924
end
2025

2126
makeClass(eval(schemaFunction), className(p+1:end))

0 commit comments

Comments
 (0)