utils.py
General-purpose utilities
user_choice(prompt, choices=('yes', 'no'), default=None)
¶
Prompts the user for confirmation. The default value, if any, is capitalized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
Information to display to the user. |
required | |
choices |
an iterable of possible choices. |
('yes', 'no')
|
|
default |
default choice |
None
|
Returns:
Type | Description |
---|---|
the user's choice |
Source code in datajoint/utils.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
get_master(full_table_name)
¶
If the table name is that of a part table, then return what the master table name would be.
This follows DataJoint's table naming convention where a master and a part must be in the
same schema and the part table is prefixed with the master table name + __
.
Example:
ephys
.session
-- master
ephys
.session__recording
-- part
Parameters:
Name | Type | Description | Default |
---|---|---|---|
full_table_name |
str
|
Full table name including part. |
required |
Returns:
Type | Description |
---|---|
str
|
Supposed master full table name or empty string if not a part table name. |
Source code in datajoint/utils.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
is_camel_case(s)
¶
Check if a string is in CamelCase notation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
string to check |
required |
Returns:
Type | Description |
---|---|
True if the string is in CamelCase notation, False otherwise Example: >>> is_camel_case("TableName") # returns True >>> is_camel_case("table_name") # returns False |
Source code in datajoint/utils.py
56 57 58 59 60 61 62 63 64 65 66 |
|
to_camel_case(s)
¶
Convert names with under score (_) separation into camel case names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
string in under_score notation |
required |
Returns:
Type | Description |
---|---|
string in CamelCase notation Example: >>> to_camel_case("table_name") # returns "TableName" |
Source code in datajoint/utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
from_camel_case(s)
¶
Convert names in camel case into underscore (_) separated names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
string in CamelCase notation |
required |
Returns:
Type | Description |
---|---|
string in under_score notation Example: >>> from_camel_case("TableName") # yields "table_name" |
Source code in datajoint/utils.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
safe_write(filepath, blob)
¶
A two-step write.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
full path |
required | |
blob |
binary data |
required |
Source code in datajoint/utils.py
105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
safe_copy(src, dest, overwrite=False)
¶
Copy the contents of src file into dest file as a two-step process. Skip if dest exists already
Source code in datajoint/utils.py
120 121 122 123 124 125 126 127 128 129 |
|
parse_sql(filepath)
¶
yield SQL statements from an SQL file
Source code in datajoint/utils.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|