materials-commons-cli 2.1.2__tar.gz → 2.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/PKG-INFO +2 -2
  2. materials_commons_cli-2.1.4/materials_commons/cli/__init__.py +1 -0
  3. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/cloned_project.py +1 -1
  4. materials_commons_cli-2.1.4/materials_commons/cli/parser.py +187 -0
  5. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/up.py +3 -6
  6. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/tree_functions.py +14 -14
  7. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/PKG-INFO +1 -1
  8. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/setup.py +1 -1
  9. materials_commons-cli-2.1.2/materials_commons/cli/__init__.py +0 -1
  10. materials_commons-cli-2.1.2/materials_commons/cli/parser.py +0 -185
  11. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/LICENSE +0 -0
  12. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/README.md +0 -0
  13. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/LICENSE.txt +0 -0
  14. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/exceptions.py +0 -0
  15. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/file_functions.py +0 -0
  16. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/functions.py +0 -0
  17. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/globus.py +0 -0
  18. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/list_objects.py +0 -0
  19. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/print_formatter.py +0 -0
  20. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/sqltable.py +0 -0
  21. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/__init__.py +0 -0
  22. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/clone.py +0 -0
  23. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/config.py +0 -0
  24. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/dataset.py +0 -0
  25. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/down.py +0 -0
  26. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/expt.py +0 -0
  27. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/fetch.py +0 -0
  28. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/globus.py +0 -0
  29. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/init.py +0 -0
  30. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/ls.py +0 -0
  31. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/mkdir.py +0 -0
  32. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/mv.py +0 -0
  33. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/proj.py +0 -0
  34. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/remote.py +0 -0
  35. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/rm.py +0 -0
  36. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/subcommands/versions.py +0 -0
  37. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/tmp_functions.py +0 -0
  38. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/treedb.py +0 -0
  39. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons/cli/user_config.py +0 -0
  40. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/SOURCES.txt +0 -0
  41. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/dependency_links.txt +0 -0
  42. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/entry_points.txt +0 -0
  43. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/not-zip-safe +0 -0
  44. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/requires.txt +0 -0
  45. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/materials_commons_cli.egg-info/top_level.txt +0 -0
  46. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/setup.cfg +0 -0
  47. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_api.py +0 -0
  48. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_functions.py +0 -0
  49. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_dataset.py +0 -0
  50. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_down.py +0 -0
  51. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_mkdir.py +0 -0
  52. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_mv.py +0 -0
  53. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_proj.py +0 -0
  54. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_rm.py +0 -0
  55. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_mc_up.py +0 -0
  56. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_treecompare_no_cache.py +0 -0
  57. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_treecompare_with_cache.py +0 -0
  58. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_treedb.py +0 -0
  59. {materials_commons-cli-2.1.2 → materials_commons_cli-2.1.4}/test/test_user_config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: materials_commons-cli
3
- Version: 2.1.2
2
+ Name: materials_commons_cli
3
+ Version: 2.1.4
4
4
  Summary: Materials Commons CLI
5
5
  Home-page: https://materials-commons.github.io/materials-commons-cli/html/index.html
6
6
  Author: Materials Commons development team
@@ -0,0 +1 @@
1
+ __version__ = '2.1.4'
@@ -183,7 +183,7 @@ class ClonedProject(object):
183
183
 
184
184
  Args:
185
185
  recursive (bool): Download directory contents recursively
186
- limit (str): File size upload limit (MB). Default="50" (50MB). Does
186
+ limit (str): File size upload limit (MB). Default="750" (750MB). Does
187
187
  not apply to Globus uploads.
188
188
  globus (bool): Use globus to download files
189
189
  label (str): Globus transfer label to make finding tasks simpler
@@ -0,0 +1,187 @@
1
+ import argparse
2
+ import json
3
+ import os
4
+ import sys
5
+ from datetime import datetime, timedelta
6
+ from io import StringIO
7
+
8
+ import materials_commons.api as mcapi
9
+ import pkg_resources
10
+ import requests
11
+
12
+ import materials_commons.cli.functions as clifuncs
13
+ from materials_commons.cli.exceptions import MCCLIException, MissingRemoteException, \
14
+ MultipleRemoteException, NoDefaultRemoteException
15
+ from materials_commons.cli.subcommands.clone import clone_subcommand
16
+ from materials_commons.cli.subcommands.config import config_subcommand
17
+ from materials_commons.cli.subcommands.dataset import DatasetSubcommand
18
+ from materials_commons.cli.subcommands.down import down_subcommand
19
+ from materials_commons.cli.subcommands.expt import ExptSubcommand
20
+ from materials_commons.cli.subcommands.fetch import fetch_subcommand
21
+ # from materials_commons.cli.subcommands.samp import SampSubcommand
22
+ from materials_commons.cli.subcommands.globus import globus_subcommand
23
+ from materials_commons.cli.subcommands.init import init_subcommand
24
+ from materials_commons.cli.subcommands.ls import ls_subcommand
25
+ from materials_commons.cli.subcommands.mkdir import mkdir_subcommand
26
+ from materials_commons.cli.subcommands.mv import mv_subcommand
27
+ # from materials_commons.cli.subcommands.proc import ProcSubcommand
28
+ from materials_commons.cli.subcommands.proj import ProjSubcommand
29
+ from materials_commons.cli.subcommands.remote import remote_subcommand
30
+ from materials_commons.cli.subcommands.rm import rm_subcommand
31
+ from materials_commons.cli.subcommands.up import up_subcommand
32
+ from materials_commons.cli.subcommands.versions import versions_subcommand
33
+ from materials_commons.cli.user_config import Config
34
+
35
+ standard_usage = [
36
+ {'name': 'remote', 'desc': 'List servers', 'subcommand': remote_subcommand},
37
+ {'name': 'proj', 'desc': 'List projects', 'subcommand': ProjSubcommand()},
38
+ {'name': 'dataset', 'desc': 'List datasets', 'subcommand': DatasetSubcommand()},
39
+ {'name': 'expt', 'desc': 'List experiments', 'subcommand': ExptSubcommand()},
40
+ {'name': 'init', 'desc': 'Initialize a new project', 'subcommand': init_subcommand},
41
+ {'name': 'clone', 'desc': 'Clone an existing project', 'subcommand': clone_subcommand},
42
+ {'name': 'ls', 'desc': 'List directory contents', 'subcommand': ls_subcommand},
43
+ {'name': 'mkdir', 'desc': 'Make directories', 'subcommand': mkdir_subcommand},
44
+ {'name': 'rm', 'desc': 'Remove files and directories', 'subcommand': rm_subcommand},
45
+ {'name': 'mv', 'desc': 'Move files', 'subcommand': mv_subcommand},
46
+ {'name': 'fetch', 'desc': 'Remote data fetching and configuration', 'subcommand': fetch_subcommand},
47
+ {'name': 'up', 'desc': 'Upload files', 'subcommand': up_subcommand},
48
+ {'name': 'down', 'desc': 'Download files', 'subcommand': down_subcommand},
49
+ {'name': 'globus', 'desc': 'Manage Globus uploads and downloads', 'subcommand': globus_subcommand},
50
+ {'name': 'versions', 'desc': 'List file versions', 'subcommand': versions_subcommand},
51
+ # {'name': 'proc', 'desc': 'List processes', 'subcommand': ProcSubcommand()},
52
+ # {'name': 'samp', 'desc': 'List samples', 'subcommand': SampSubcommand()},
53
+ {'name': 'config', 'desc': 'Configure `mc`', 'subcommand': config_subcommand}
54
+ ]
55
+ standard_interfaces = {d['name']: d for d in standard_usage}
56
+
57
+
58
+ def make_parser():
59
+ usage_help = StringIO()
60
+ usage_help.write("mc <command> [<args>]\n\n")
61
+ usage_help.write("The standard mc commands are:\n")
62
+
63
+ for name, interface in standard_interfaces.items():
64
+ usage_help.write(" {:10} {:40}\n".format(name, interface['desc']))
65
+
66
+ parser = argparse.ArgumentParser(
67
+ description='Materials Commons command line interface',
68
+ usage=usage_help.getvalue())
69
+ parser.add_argument('command', help='Subcommand to run')
70
+ parser.add_argument('--version', '-v', action='version',
71
+ version=pkg_resources.get_distribution('materials-commons-cli').version)
72
+
73
+ return parser
74
+
75
+
76
+ CLI_VERSION_CACHE_FILE = os.path.expanduser('~/.materialscommons/.cli-version-cache.json')
77
+
78
+
79
+ def should_check_version():
80
+ try:
81
+ if os.path.exists(CLI_VERSION_CACHE_FILE):
82
+ with open(CLI_VERSION_CACHE_FILE) as f:
83
+ cache = json.load(f)
84
+ last_check = datetime.fromisoformat(cache['last_check'])
85
+ # Only check once per day
86
+ if datetime.now() - last_check < timedelta(days=1):
87
+ return False
88
+ except Exception:
89
+ pass
90
+ return True
91
+
92
+
93
+ def update_version_cache():
94
+ try:
95
+ with open(CLI_VERSION_CACHE_FILE, 'w') as f:
96
+ json.dump({
97
+ 'last_check': datetime.now().isoformat()
98
+ }, f)
99
+ except Exception:
100
+ pass
101
+
102
+
103
+ def check_package_version():
104
+ if not should_check_version():
105
+ return
106
+
107
+ package_name = 'materials-commons-cli'
108
+ try:
109
+ current_version = pkg_resources.get_distribution(package_name).version
110
+ response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
111
+ latest_version = response.json()["info"]["version"]
112
+
113
+ if current_version != latest_version:
114
+ print(
115
+ f"\nWarning: You are using an older version of the Materials Commons CLI ({current_version}).\n"
116
+ f"A newer version is available ({latest_version}).\n"
117
+ f"It is recommended you upgrade to the newest version: pip install --upgrade {package_name}\n",
118
+ file=sys.stderr,
119
+ )
120
+
121
+ update_version_cache()
122
+
123
+ except Exception as e:
124
+ pass
125
+
126
+
127
+ def main(argv=None, working_dir=None):
128
+ if argv is None:
129
+ argv = sys.argv
130
+ if working_dir is None:
131
+ working_dir = os.getcwd()
132
+ try:
133
+
134
+ config = Config()
135
+ if config.REST_logging:
136
+ mcapi.Client.set_debug_on()
137
+ pass
138
+
139
+ parser = make_parser()
140
+
141
+ if len(argv) < 2:
142
+ parser.print_help()
143
+ return 1
144
+
145
+ # parse_args defaults to [1:] for args, but you need to
146
+ # exclude the rest of the args too, or validation will fail
147
+ args = parser.parse_args(argv[1:2])
148
+
149
+ if args.command in standard_interfaces:
150
+ result = standard_interfaces[args.command]['subcommand'](argv[2:], working_dir)
151
+ check_package_version()
152
+ return result
153
+
154
+ else:
155
+ print('Unrecognized command')
156
+ parser.print_help()
157
+ return 1
158
+
159
+ except MissingRemoteException as e:
160
+ print("Error:", e)
161
+ clifuncs.print_remote_help()
162
+ return 1
163
+
164
+ except MultipleRemoteException as e:
165
+ print("Error:", e)
166
+ print(
167
+ '** Please edit .mc/config.json to include `"remote":{"mcurl": "Materials Commons https address here","email": "YOUR_EMAIL_HERE"}` **')
168
+ return 1
169
+
170
+ except NoDefaultRemoteException as e:
171
+ print("Error:", e)
172
+ print("Set the default remote with:")
173
+ print(" mc remote --set-default EMAIL URL")
174
+ clifuncs.print_remote_help()
175
+ return 1
176
+
177
+ except MCCLIException as e:
178
+ print("CLI Error:", e)
179
+ return 1
180
+
181
+ except mcapi.MCAPIError as e:
182
+ import json
183
+ print("API Error:", e)
184
+ print("Writing error message to 'mcapi_error.json'")
185
+ with open('mcapi_error.json', 'w') as f:
186
+ json.dump(e.response.json(), f, indent=2)
187
+ return 1
@@ -1,15 +1,12 @@
1
1
  import argparse
2
- import os
3
- import sys
4
- import time
5
2
 
6
3
  import materials_commons.cli.exceptions as cliexcept
7
4
  import materials_commons.cli.functions as clifuncs
8
5
  import materials_commons.cli.globus as cliglobus
9
- import materials_commons.cli.file_functions as filefuncs
10
6
  import materials_commons.cli.tree_functions as treefuncs
11
7
  from materials_commons.cli.treedb import LocalTree, RemoteTree
12
8
 
9
+
13
10
  def make_parser():
14
11
  """Make argparse.ArgumentParser for `mc up`"""
15
12
 
@@ -29,8 +26,8 @@ def make_parser():
29
26
  parser.add_argument('paths', nargs='*', default=None, help='Files or directories')
30
27
  parser.add_argument('-r', '--recursive', action="store_true", default=False,
31
28
  help='Upload directory contents recursively')
32
- parser.add_argument('--limit', nargs=1, type=float, default=[250],
33
- help='File size upload limit (MB). Default=250MB. Does not apply to Globus uploads.')
29
+ parser.add_argument('--limit', nargs=1, type=float, default=[750],
30
+ help='File size upload limit (MB). Default=750MB. Max size is also 750MB. Does not apply to Globus uploads.')
34
31
  parser.add_argument('-g', '--globus', action="store_true", default=False,
35
32
  help=globus_help)
36
33
  parser.add_argument('--label', nargs=1, type=str,
@@ -112,7 +112,7 @@ def make_mcpaths_for_upload(proj_local_path, paths):
112
112
  _paths.append(path)
113
113
  return _paths
114
114
 
115
- def upload_file(proj, local_abspath, mcpath, working_dir, parent_id=None, limit=50, remotetree=None, update_remotetree=True):
115
+ def upload_file(proj, local_abspath, mcpath, working_dir, parent_id=None, limit=750, remotetree=None, update_remotetree=True):
116
116
  """Upload one file
117
117
 
118
118
  Notes:
@@ -208,7 +208,7 @@ def upload_file(proj, local_abspath, mcpath, working_dir, parent_id=None, limit=
208
208
  print("uploaded:", printpath, "as", printdestpath)
209
209
  return (file_result, error_result)
210
210
 
211
- def check_and_upload_file(proj, local_abspath, working_dir, limit=50, no_compare=False,
211
+ def check_and_upload_file(proj, local_abspath, working_dir, limit=750, no_compare=False,
212
212
  upload_as=None, localtree=None, remotetree=None, parent_id=None, child_data=None,
213
213
  update_remotetree=True):
214
214
  """Checks validity and upload one file
@@ -257,8 +257,8 @@ def check_and_upload_file(proj, local_abspath, working_dir, limit=50, no_compare
257
257
  error_results: str
258
258
  Error messages for unsuccessful file uploads
259
259
  """
260
- file_result = None
261
- error_result = None
260
+ file_results = {}
261
+ error_results = {}
262
262
 
263
263
  printpath = os.path.relpath(local_abspath, start=working_dir)
264
264
 
@@ -281,14 +281,14 @@ def check_and_upload_file(proj, local_abspath, working_dir, limit=50, no_compare
281
281
  if child_data[mcpath]['r_type'] == 'directory':
282
282
  msg = printpath + ": remote is directory (skipping)"
283
283
  print(msg)
284
- error_resuts[local_abspath] = msg
284
+ error_results[local_abspath] = msg
285
285
  return (file_results, error_results)
286
286
 
287
287
  # if local and remote files exists, and checksums known and match -> skip, continue
288
288
  if 'eq' in child_data[mcpath] and child_data[mcpath]['eq'] is True:
289
289
  msg = printpath + ": local is equivalent to remote (skipping)"
290
290
  print(msg)
291
- error_resuts[child_local_abspath] = msg
291
+ # error_results[child_local_abspath] = msg
292
292
  return (file_results, error_results)
293
293
 
294
294
  # else, get parent_id if not already known (might be None)
@@ -305,7 +305,7 @@ def check_and_upload_file(proj, local_abspath, working_dir, limit=50, no_compare
305
305
  if mcpath in dirs_data and dirs_data[mcpath]['r_type'] == 'directory':
306
306
  msg = printpath + ": remote is directory (skipping)"
307
307
  print(msg)
308
- return (file_result, msg)
308
+ return (file_results, msg)
309
309
 
310
310
  # if remote file exists
311
311
  if mcpath in files_data:
@@ -315,7 +315,7 @@ def check_and_upload_file(proj, local_abspath, working_dir, limit=50, no_compare
315
315
  if 'eq' in file_data and file_data['eq'] is True:
316
316
  msg = printpath + ": local is equivalent to remote (skipping)"
317
317
  print(msg)
318
- return (file_result, msg)
318
+ return (file_results, msg)
319
319
 
320
320
  # else, get parent_id if not already known (still might be None)
321
321
  if parent_id is None:
@@ -354,7 +354,7 @@ def filter_local_abspaths(proj_local_path, local_abspaths, working_dir):
354
354
  return _local_abspaths
355
355
 
356
356
 
357
- def check_and_upload_directory(proj, local_abspath, working_dir, limit=50,
357
+ def check_and_upload_directory(proj, local_abspath, working_dir, limit=750,
358
358
  no_compare=False, upload_as=None, localtree=None, remotetree=None, parent_id=None):
359
359
  """Checks validity and uploads a directory and contents recursively
360
360
 
@@ -466,7 +466,7 @@ def check_and_upload_directory(proj, local_abspath, working_dir, limit=50,
466
466
  if os.path.isfile(child_local_abspath):
467
467
 
468
468
  file_result, error_msg = check_and_upload_file(proj, child_local_abspath, working_dir,
469
- limit=50, no_compare=no_compare, upload_as=child_upload_as, localtree=localtree,
469
+ limit=limit, no_compare=no_compare, upload_as=child_upload_as, localtree=localtree,
470
470
  remotetree=remotetree, parent_id=id, child_data=child_data, update_remotetree=True)
471
471
 
472
472
  if file_result is not None:
@@ -494,7 +494,7 @@ def check_and_upload_directory(proj, local_abspath, working_dir, limit=50,
494
494
  return (file_results, error_results)
495
495
 
496
496
 
497
- def standard_upload_v2(proj, paths, working_dir, recursive=False, limit=50, no_compare=False, upload_as=None, localtree=None, remotetree=None):
497
+ def standard_upload_v2(proj, paths, working_dir, recursive=False, limit=750, no_compare=False, upload_as=None, localtree=None, remotetree=None):
498
498
  """Upload files and directories to Materials Commons
499
499
 
500
500
  Args:
@@ -590,7 +590,7 @@ def standard_upload_v2(proj, paths, working_dir, recursive=False, limit=50, no_c
590
590
 
591
591
 
592
592
 
593
- def standard_upload(proj, paths, working_dir, recursive=False, limit=50, no_compare=False, upload_as=None, localtree=None, remotetree=None):
593
+ def standard_upload(proj, paths, working_dir, recursive=False, limit=750, no_compare=False, upload_as=None, localtree=None, remotetree=None):
594
594
  """Upload files to Materials Commons
595
595
 
596
596
  Args:
@@ -1270,7 +1270,7 @@ class _Mover(object):
1270
1270
  print(dest_printpath + ": does not exist on remote (may not rename multiple src)")
1271
1271
  valid_usage = False
1272
1272
  elif self.dest_remote_type != 'directory':
1273
- raise cliexcept.MCCLIException("Error in mv: dest_path='" + dest_path + "', dest_remote_type='" + str(dest_remote_type) + "'")
1273
+ raise cliexcept.MCCLIException("Error in mv: dest_path='" + dest_path + "', dest_remote_type='" + str(self.dest_remote_type) + "'")
1274
1274
 
1275
1275
  # check local dest type
1276
1276
  if not self.remote_only:
@@ -1283,7 +1283,7 @@ class _Mover(object):
1283
1283
  print(dest_printpath + ": does not exist locally (may not rename multiple src)")
1284
1284
  valid_usage = False
1285
1285
  elif self.dest_local_type != 'directory':
1286
- raise cliexcept.MCCLIException("Error in mv: dest_path='" + dest_path + "', dest_remote_type='" + str(dest_local_type) + "'")
1286
+ raise cliexcept.MCCLIException("Error in mv: dest_path='" + dest_path + "', dest_remote_type='" + str(self.dest_local_type) + "'")
1287
1287
 
1288
1288
  if self.dest_remote_type != self.dest_local_type:
1289
1289
  print(dest_printpath + ": local and remote types do not match")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: materials-commons-cli
3
- Version: 2.1.2
3
+ Version: 2.1.4
4
4
  Summary: Materials Commons CLI
5
5
  Home-page: https://materials-commons.github.io/materials-commons-cli/html/index.html
6
6
  Author: Materials Commons development team
@@ -4,7 +4,7 @@ from setuptools import setup, find_namespace_packages
4
4
  from materials_commons.cli import __version__
5
5
 
6
6
  setup(
7
- name='materials_commons-cli',
7
+ name='materials_commons_cli',
8
8
  version=__version__,
9
9
  description='Materials Commons CLI',
10
10
  long_description="""This package contains the materials_commons.cli module. This module is an interface
@@ -1 +0,0 @@
1
- __version__ = '2.1.2'
@@ -1,185 +0,0 @@
1
- import argparse
2
- import json
3
- import os
4
- import sys
5
- from datetime import datetime, timedelta
6
- from io import StringIO
7
-
8
- import materials_commons.api as mcapi
9
- import pkg_resources
10
- import requests
11
-
12
- import materials_commons.cli.functions as clifuncs
13
- from materials_commons.cli.exceptions import MCCLIException, MissingRemoteException, \
14
- MultipleRemoteException, NoDefaultRemoteException
15
- from materials_commons.cli.subcommands.clone import clone_subcommand
16
- from materials_commons.cli.subcommands.config import config_subcommand
17
- from materials_commons.cli.subcommands.dataset import DatasetSubcommand
18
- from materials_commons.cli.subcommands.down import down_subcommand
19
- from materials_commons.cli.subcommands.expt import ExptSubcommand
20
- from materials_commons.cli.subcommands.fetch import fetch_subcommand
21
- # from materials_commons.cli.subcommands.samp import SampSubcommand
22
- from materials_commons.cli.subcommands.globus import globus_subcommand
23
- from materials_commons.cli.subcommands.init import init_subcommand
24
- from materials_commons.cli.subcommands.ls import ls_subcommand
25
- from materials_commons.cli.subcommands.mkdir import mkdir_subcommand
26
- from materials_commons.cli.subcommands.mv import mv_subcommand
27
- # from materials_commons.cli.subcommands.proc import ProcSubcommand
28
- from materials_commons.cli.subcommands.proj import ProjSubcommand
29
- from materials_commons.cli.subcommands.remote import remote_subcommand
30
- from materials_commons.cli.subcommands.rm import rm_subcommand
31
- from materials_commons.cli.subcommands.up import up_subcommand
32
- from materials_commons.cli.subcommands.versions import versions_subcommand
33
- from materials_commons.cli.user_config import Config
34
-
35
- standard_usage = [
36
- {'name': 'remote', 'desc': 'List servers', 'subcommand': remote_subcommand},
37
- {'name': 'proj', 'desc': 'List projects', 'subcommand': ProjSubcommand()},
38
- {'name': 'dataset', 'desc': 'List datasets', 'subcommand': DatasetSubcommand()},
39
- {'name': 'expt', 'desc': 'List experiments', 'subcommand': ExptSubcommand()},
40
- {'name': 'init', 'desc': 'Initialize a new project', 'subcommand': init_subcommand},
41
- {'name': 'clone', 'desc': 'Clone an existing project', 'subcommand': clone_subcommand},
42
- {'name': 'ls', 'desc': 'List directory contents', 'subcommand': ls_subcommand},
43
- {'name': 'mkdir', 'desc': 'Make directories', 'subcommand': mkdir_subcommand},
44
- {'name': 'rm', 'desc': 'Remove files and directories', 'subcommand': rm_subcommand},
45
- {'name': 'mv', 'desc': 'Move files', 'subcommand': mv_subcommand},
46
- {'name': 'fetch', 'desc': 'Remote data fetching and configuration', 'subcommand': fetch_subcommand},
47
- {'name': 'up', 'desc': 'Upload files', 'subcommand': up_subcommand},
48
- {'name': 'down', 'desc': 'Download files', 'subcommand': down_subcommand},
49
- {'name': 'globus', 'desc': 'Manage Globus uploads and downloads', 'subcommand': globus_subcommand},
50
- {'name': 'versions', 'desc': 'List file versions', 'subcommand': versions_subcommand},
51
- # {'name': 'proc', 'desc': 'List processes', 'subcommand': ProcSubcommand()},
52
- # {'name': 'samp', 'desc': 'List samples', 'subcommand': SampSubcommand()},
53
- {'name': 'config', 'desc': 'Configure `mc`', 'subcommand': config_subcommand}
54
- ]
55
- standard_interfaces = {d['name']: d for d in standard_usage}
56
-
57
-
58
- def make_parser():
59
- usage_help = StringIO()
60
- usage_help.write("mc <command> [<args>]\n\n")
61
- usage_help.write("The standard mc commands are:\n")
62
-
63
- for name, interface in standard_interfaces.items():
64
- usage_help.write(" {:10} {:40}\n".format(name, interface['desc']))
65
-
66
- parser = argparse.ArgumentParser(
67
- description='Materials Commons command line interface',
68
- usage=usage_help.getvalue())
69
- parser.add_argument('command', help='Subcommand to run')
70
-
71
- return parser
72
-
73
-
74
- CLI_VERSION_CACHE_FILE = os.path.expanduser('~/.materialscommons/.cli-version-cache.json')
75
-
76
-
77
- def should_check_version():
78
- try:
79
- if os.path.exists(CLI_VERSION_CACHE_FILE):
80
- with open(CLI_VERSION_CACHE_FILE) as f:
81
- cache = json.load(f)
82
- last_check = datetime.fromisoformat(cache['last_check'])
83
- # Only check once per day
84
- if datetime.now() - last_check < timedelta(days=1):
85
- return False
86
- except Exception:
87
- pass
88
- return True
89
-
90
-
91
- def update_version_cache():
92
- try:
93
- with open(CLI_VERSION_CACHE_FILE, 'w') as f:
94
- json.dump({
95
- 'last_check': datetime.now().isoformat()
96
- }, f)
97
- except Exception:
98
- pass
99
-
100
-
101
- def check_package_version():
102
- if not should_check_version():
103
- return
104
-
105
- package_name = 'materials-commons-cli'
106
- try:
107
- current_version = pkg_resources.get_distribution(package_name).version
108
- response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
109
- latest_version = response.json()["info"]["version"]
110
-
111
- if current_version != latest_version:
112
- print(
113
- f"\nWarning: You are using an older version of the Materials Commons CLI ({current_version}).\n"
114
- f"A newer version is available ({latest_version}).\n"
115
- f"It is recommended you upgrade to the newest version: pip install --upgrade {package_name}\n",
116
- file=sys.stderr,
117
- )
118
-
119
- update_version_cache()
120
-
121
- except Exception as e:
122
- pass
123
-
124
-
125
- def main(argv=None, working_dir=None):
126
- if argv is None:
127
- argv = sys.argv
128
- if working_dir is None:
129
- working_dir = os.getcwd()
130
- try:
131
-
132
- config = Config()
133
- if config.REST_logging:
134
- mcapi.Client.set_debug_on()
135
- pass
136
-
137
- parser = make_parser()
138
-
139
- if len(argv) < 2:
140
- parser.print_help()
141
- return 1
142
-
143
- # parse_args defaults to [1:] for args, but you need to
144
- # exclude the rest of the args too, or validation will fail
145
- args = parser.parse_args(argv[1:2])
146
-
147
- if args.command in standard_interfaces:
148
- result = standard_interfaces[args.command]['subcommand'](argv[2:], working_dir)
149
- check_package_version()
150
- return result
151
-
152
- else:
153
- print('Unrecognized command')
154
- parser.print_help()
155
- return 1
156
-
157
- except MissingRemoteException as e:
158
- print("Error:", e)
159
- clifuncs.print_remote_help()
160
- return 1
161
-
162
- except MultipleRemoteException as e:
163
- print("Error:", e)
164
- print(
165
- '** Please edit .mc/config.json to include `"remote":{"mcurl": "Materials Commons https address here","email": "YOUR_EMAIL_HERE"}` **')
166
- return 1
167
-
168
- except NoDefaultRemoteException as e:
169
- print("Error:", e)
170
- print("Set the default remote with:")
171
- print(" mc remote --set-default EMAIL URL")
172
- clifuncs.print_remote_help()
173
- return 1
174
-
175
- except MCCLIException as e:
176
- print("CLI Error:", e)
177
- return 1
178
-
179
- except mcapi.MCAPIError as e:
180
- import json
181
- print("API Error:", e)
182
- print("Writing error message to 'mcapi_error.json'")
183
- with open('mcapi_error.json', 'w') as f:
184
- json.dump(e.response.json(), f, indent=2)
185
- return 1