forked from LorenFrankLab/spyglass
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate utils from
config/
scripts (LorenFrankLab#662)
* Contrib doc edits * LorenFrankLab#531 * LorenFrankLab#532: PR Template * Fix numbering * Typo * LorenFrankLab#658 config. Start to phase out config dir * Update changelog * Add docstrings. Separate sql content from funcs
- Loading branch information
Showing
12 changed files
with
489 additions
and
274 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 |
---|---|---|
@@ -1,31 +1,12 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
|
||
def add_collab_user(user_name): | ||
# create a temporary file for the command | ||
file = tempfile.NamedTemporaryFile(mode="w") | ||
|
||
# Create the user (if not already created) and set the password | ||
file.write( | ||
f"CREATE USER IF NOT EXISTS '{user_name}'@'%' IDENTIFIED BY 'temppass';\n" | ||
) | ||
|
||
# Grant privileges to databases matching the user_name pattern | ||
file.write( | ||
f"GRANT ALL PRIVILEGES ON `{user_name}\_%`.* TO '{user_name}'@'%';\n" | ||
) | ||
|
||
# Grant SELECT privileges on all databases | ||
file.write(f"GRANT SELECT ON `%`.* TO '{user_name}'@'%';\n") | ||
|
||
file.flush() | ||
|
||
# run those commands in sql | ||
os.system(f"mysql -p -h lmf-db.cin.ucsf.edu < {file.name}") | ||
from warnings import warn | ||
|
||
from spyglass.utils.database_settings import DatabaseSettings | ||
|
||
if __name__ == "__main__": | ||
add_collab_user(sys.argv[1]) | ||
warn( | ||
"This script is deprecated. " | ||
+ "Use spyglass.utils.database_settings.DatabaseSettings instead." | ||
) | ||
DatabaseSettings(user_name=sys.argv[1]).add_collab_user() |
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 |
---|---|---|
@@ -1,36 +1,12 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
shared_modules = [ | ||
"common\_%", | ||
"spikesorting\_%", | ||
"decoding\_%", | ||
"position\_%", | ||
"position_linearization\_%", | ||
"ripple\_%", | ||
"lfp\_%", | ||
] | ||
|
||
|
||
def add_user(user_name): | ||
# create a temporary file for the command | ||
file = tempfile.NamedTemporaryFile(mode="w") | ||
|
||
# Create the user (if not already created) and set password | ||
file.write( | ||
f"CREATE USER IF NOT EXISTS '{user_name}'@'%' IDENTIFIED BY 'Data_$haring';\n" | ||
) | ||
|
||
# Grant privileges | ||
file.write(f"GRANT SELECT ON `%`.* TO '{user_name}'@'%';\n") | ||
|
||
file.flush() | ||
|
||
# run those commands in sql | ||
os.system(f"mysql -p -h lmf-db.cin.ucsf.edu < {file.name}") | ||
from warnings import warn | ||
|
||
from spyglass.utils.database_settings import DatabaseSettings | ||
|
||
if __name__ == "__main__": | ||
add_user(sys.argv[1]) | ||
warn( | ||
"This script is deprecated. " | ||
+ "Use spyglass.utils.database_settings.DatabaseSettings instead." | ||
) | ||
DatabaseSettings(user_name=sys.argv[1]).add_dj_guest() |
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 |
---|---|---|
@@ -1,40 +1,12 @@ | ||
#!/usr/bin/env python | ||
import grp | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
TARGET_GROUP = "kachery-users" | ||
|
||
|
||
def add_module(module_name): | ||
print(f"Granting everyone permissions to module {module_name}") | ||
|
||
# create a tempoary file for the command | ||
file = tempfile.NamedTemporaryFile(mode="w") | ||
|
||
# find the kachery-users group | ||
groups = grp.getgrall() | ||
group_found = False # initialize the flag as False | ||
for group in groups: | ||
if group.gr_name == TARGET_GROUP: | ||
group_found = True # set the flag to True when the group is found | ||
break | ||
|
||
# Check if the group was found | ||
if not group_found: | ||
sys.exit(f"Error: The target group {TARGET_GROUP} was not found.") | ||
|
||
# get a list of usernames | ||
for user in group.gr_mem: | ||
file.write( | ||
f"GRANT ALL PRIVILEGES ON `{module_name}\_%`.* TO `{user}`@'%';\n" | ||
) | ||
file.flush() | ||
|
||
# run those commands in sql | ||
os.system(f"mysql -p -h lmf-db.cin.ucsf.edu < {file.name}") | ||
from warnings import warn | ||
|
||
from spyglass.utils.database_settings import DatabaseSettings | ||
|
||
if __name__ == "__main__": | ||
add_module(sys.argv[1]) | ||
warn( | ||
"This script is deprecated. " | ||
+ "Use spyglass.utils.database_settings.DatabaseSettings instead." | ||
) | ||
DatabaseSettings().add_module(sys.argv[1]) |
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 |
---|---|---|
@@ -1,44 +1,12 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
shared_modules = [ | ||
"common\_%", | ||
"spikesorting\_%", | ||
"decoding\_%", | ||
"position\_%", | ||
"position_linearization\_%", | ||
"ripple\_%", | ||
"lfp\_%", | ||
] | ||
|
||
|
||
def add_user(user_name): | ||
if os.path.isdir(f"/home/{user_name}"): | ||
print("Creating database user ", user_name) | ||
else: | ||
sys.exit(f"Error: user_name {user_name} does not exist in /home.") | ||
|
||
# create a tempoary file for the command | ||
file = tempfile.NamedTemporaryFile(mode="w") | ||
create_user_query = f"CREATE USER IF NOT EXISTS '{user_name}'@'%' IDENTIFIED BY 'temppass';\n" | ||
grant_privileges_query = ( | ||
f"GRANT ALL PRIVILEGES ON `{user_name}\_%`.* TO '{user_name}'@'%';" | ||
) | ||
|
||
file.write(create_user_query + "\n") | ||
file.write(grant_privileges_query + "\n") | ||
for module in shared_modules: | ||
file.write( | ||
f"GRANT ALL PRIVILEGES ON `{module}`.* TO '{user_name}'@'%';\n" | ||
) | ||
file.write(f"GRANT SELECT ON `%`.* TO '{user_name}'@'%';\n") | ||
file.flush() | ||
|
||
# run those commands in sql | ||
os.system(f"mysql -p -h lmf-db.cin.ucsf.edu < {file.name}") | ||
from warnings import warn | ||
|
||
from spyglass.utils.database_settings import DatabaseSettings | ||
|
||
if __name__ == "__main__": | ||
add_user(sys.argv[1]) | ||
warn( | ||
"This script is deprecated. " | ||
+ "Use spyglass.utils.database_settings.DatabaseSettings instead." | ||
) | ||
DatabaseSettings(user_name=sys.argv[1]).add_dj_user() |
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
Oops, something went wrong.