plotterparameters.py 5.41 KB
Newer Older
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.cmdline module of the BEAT platform.          #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################


"""Usage:
  %(prog)s plotterparameters list
  %(prog)s plotterparameters check [<name>]...
  %(prog)s plotterparameters pull [--force] [<name>]...
  %(prog)s plotterparameters create <name>...
  %(prog)s plotterparameters version <name>
  %(prog)s plotterparameters fork <src> <dst>
  %(prog)s plotterparameters rm <name>...
  %(prog)s plotterparameters --help


Commands:
  list      Lists all the plotterparameters available locally
  check     Checks a local plotterparameter for validity
  create    Creates a new local plotterparameter
  version   Creates a new version of an existing plotterparameter
  fork      Forks a local plotterparameter
  rm        Deletes a local plotterparameter


Options:
  --force    Performs operation regardless of conflicts
  --dry-run  Doesn't really perform the task, just comments what would do
  --help     Display this screen

"""

import simplejson
import collections
from .dataformats import pull as dataformats_pull

import logging
logger = logging.getLogger(__name__)

from . import common


def pull(webapi, prefix, names, force, indentation, format_cache):
    """Copies plotterparameters from the server.

    Parameters:

      webapi (object): An instance of our WebAPI class, prepared to access the
        BEAT server of interest

      prefix (str): A string representing the root of the path in which the
        user objects are stored

      names (list): A list of strings, each representing the unique relative
        path of the objects to retrieve or a list of usernames from which to
        retrieve objects. If the list is empty, then we pull all available
        objects of a given type. If no user is set, then pull all public
        objects of a given type.

      force (bool): If set to ``True``, then overwrites local changes with the
        remotely retrieved copies.

      indentation (int): The indentation level, useful if this function is
        called recursively while downloading different object types. This is
        normally set to ``0`` (zero).


    Returns:

      int: Indicating the exit status of the command, to be reported back to
        the calling process. This value should be zero if everything works OK,
        otherwise, different than zero (POSIX compliance).

    """

    # download required plotterparameter
    status, names = common.pull(webapi, prefix, 'plotterparameter', names,
                                ['data', 'short_description', 'plotter'], force,
                                indentation)

    return status

def process(args):

  if args['list']:
    return common.display_local_list(args['config'].path, 'plotterparameter')

  elif args['check']:
    return common.check(args['config'].path, 'plotterparameter', args['<name>'])

  elif args['pull']:
    with common.make_webapi(args['config']) as webapi:
      args['<name>'] = common.make_up_remote_list(webapi, 'plotterparameter',
                                                  args['<name>'])
      if args['<name>'] is None: return 1 #error
      return pull(webapi, args['config'].path, args['<name>'],
                  args['--force'], 0, {})

  elif args['create']:
    return common.create(args['config'].path, 'plotterparameter', args['<name>'])

  elif args['version']:
    return common.new_version(args['config'].path, 'plotterparameter',
                              args['<name>'][0])

  elif args['fork']:
    return common.fork(args['config'].path, 'plotterparameter', args['<src>'],
                       args['<dst>'])

  elif args['rm']:
    return common.delete_local(args['config'].path, 'plotterparameter', args['<name>'])

  return 1