-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathmove_data_files.py
More file actions
executable file
·66 lines (58 loc) · 2.64 KB
/
Copy pathmove_data_files.py
File metadata and controls
executable file
·66 lines (58 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
Move data_files directory from default location (sys.prefix) or specified location
to chosen directory.
Results in PmagPy-data directory which contains notebooks and data_files.
"""
import shutil
import sys
import os
from os import path
import glob
from pmagpy import pmag
from pmagpy import find_pmag_dir
def copy_directory(src, dest):
dest = path.join(dest, 'data_files')
print('-I- Copying {} to {}'.format(src, dest))
try:
shutil.copytree(src, dest)
# Directories are the same
except shutil.Error as error:
print('-W- Directory not copied. Error: %s' % error)
# Any error saying that the directory doesn't exist
except OSError as error:
print('-W- Directory not copied. Error: %s' % error)
print(" If you have a developer install, move_data_files.py won't work. Simply navigate to your PmagPy directory. You can find the data_files directory and all PmagPy notebooks there.")
def main():
if '-h' in sys.argv:
print(" Help for move_data_files.py:")
print(" Choose the folder where you want the PmagPy data files to be.")
print(" Navigate to that folder, and use the command: 'move_data_files.py'")
print(" Alternatively, you may use the full path to the directory of your choice from anywhere in the file system, using the '-d' flag: 'move_data_files.py -d /Users/***/Desktop' where *** is your username")
print(" **IMPORTANT** If you have a developer install, move_data_files.py won't work. Simply navigate to your PmagPy directory. You can find the data_files directory and all PmagPy notebooks there.")
sys.exit()
# create PmagPy-data directory
dest = pmag.get_named_arg('-d', '.', False)
dest = path.realpath(dest)
dest = path.join(dest, 'PmagPy-data')
if not path.exists(dest):
try:
os.mkdir(dest)
except FileNotFoundError:
pass
# get source of data_files
source = pmag.get_named_arg('-s', sys.prefix, False)
source = path.realpath(source)
if source.endswith('data_files') or source.endswith('data_files/'):
source = path.split(source)[0]
# copy data_files to PmagPy-data directory
data_files = path.join(source, 'data_files')
copy_directory(data_files, dest)
# now try to get notebooks
pmagpy_dir = find_pmag_dir.get_pmag_dir()
# needs all the notebooks
for notebook_location in glob.glob(path.join(source, "data_files", "PmagPy*.ipynb")):
notebook_name = os.path.split(notebook_location)[1]
shutil.copy(notebook_location, path.join(dest, notebook_name))
if __name__ == "__main__":
main()