def main():
    parser = argparse.ArgumentParser(description="Create a location file")
    parser.add_argument("--lat", action="store", dest="latitude", type=float, required=True)
    parser.add_argument("--lon", action="store", dest="longitude", type=float, required=True)
    parser.add_argument("--name", action="store", dest="name", type=str, required=True)
    parser.add_argument("--filename", action="store", dest="filename", type=str, required=True)

    args = parser.parse_args()

    env = bootstrap("../development.ini")
    location_file_dir = env["registry"].settings.location_file_dir
    path = os.path.join(location_file_dir, args.filename)

    # Save all arguments except 'filename' in the new config.json file.
    data = args.__dict__
    filename = data.pop("filename")

    try:
        json_config = util.create_location_file(path, **data)
    except util.LocationFileExists:
        print >> sys.stderr, 'A location file with the name "%s" already ' "exists." % filename
        exit(1)

    else:
        print "Create location file: %s" % path
        print "Contents of config.json: \n%s" % json_config

    env["closer"]()
Beispiel #2
0
    def post(self):
        data = self.request.validated
        location_dir = data.pop('location_dir')
        model = data.pop('model')
        model_data = data.pop('model_data')
        _map = model_data.get('map', None)

        # Create a directory skeleton for the location file.
        util.create_location_file(location_dir, **data)

        # If a map was specified, move it into the new location file directory.
        if _map and _map['filename']:
            filename = _map['filename']
            old = os.path.join(model.base_dir, filename)
            new = os.path.join(data['location_dir'], filename)
            os.rename(old, new)

        with open(os.path.join(location_dir, 'location.json')) as f:
            f.write(json.dumps(model_data, default=util.json_encoder))

        return {
            'location': data['name'],
        }
    def post(self):
        data = self.request.validated
        location_dir = data.pop('location_dir')
        model = data.pop('model')
        model_data = data.pop('model_data')
        _map = model_data.get('map', None)

        # Create a directory skeleton for the location file.
        util.create_location_file(location_dir, **data)

        # If a map was specified, move it into the new location file directory.
        if _map and _map['filename']:
            filename = _map['filename']
            old = os.path.join(model.base_dir, filename)
            new = os.path.join(data['location_dir'], filename)
            os.rename(old, new)

        with open(os.path.join(location_dir, 'location.json')) as f:
            f.write(json.dumps(model_data, default=util.json_encoder))

        return {
            'location': data['name'],
        }
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser(description='Create a location file')
    parser.add_argument('--lat',
                        action='store',
                        dest='latitude',
                        type=float,
                        required=True)
    parser.add_argument('--lon',
                        action='store',
                        dest='longitude',
                        type=float,
                        required=True)
    parser.add_argument('--name',
                        action='store',
                        dest='name',
                        type=str,
                        required=True)
    parser.add_argument('--filename',
                        action='store',
                        dest='filename',
                        type=str,
                        required=True)

    args = parser.parse_args()

    env = bootstrap('../development.ini')
    location_file_dir = env['registry'].settings.location_file_dir
    path = os.path.join(location_file_dir, args.filename)

    # Save all arguments except 'filename' in the new config.json file.
    data = args.__dict__
    filename = data.pop('filename')

    try:
        json_config = util.create_location_file(path, **data)
    except util.LocationFileExists:
        print >> sys.stderr, 'A location file with the name "%s" already ' \
                             'exists.' % filename
        exit(1)

    else:
        print 'Create location file: %s' % path
        print 'Contents of config.json: \n%s' % json_config

    env['closer']()