-
Notifications
You must be signed in to change notification settings - Fork 1
/
neoget.py
90 lines (76 loc) · 2.78 KB
/
neoget.py
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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Copyright (c) 2002-2015 "Neo Technology,"
# Network Engine for Objects in Lund AB [http://neotechnology.com]
#
# This file is part of Neo4j.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Usage: neoget.py <cmd> [arg]
-v neo4j-version: download this specific neo4j version
-l download-url : download neo4j provided by this url
-h : show this help message
Example: neoget.py -v 2.3.1
neoget.py -h
"""
from __future__ import print_function
from urllib import urlretrieve
from sys import argv, stdout, exit
from getopt import getopt
from os import path, name
from zipfile import ZipFile
from tarfile import TarFile
from urlparse import urlparse
DIST = "http://dist.neo4j.org"
DEFAULT_URL = "http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-M01-NIGHTLY-unix.tar.gz"
WIN_URL = "http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-M01-NIGHTLY-windows.zip"
def main():
is_windows = (name == 'nt')
archive_url = WIN_URL if is_windows else DEFAULT_URL
archive_name = path.split(urlparse(archive_url).path)[-1]
try:
opts, args = getopt(argv[1:], "hv:l:")
except getopt.GetoptError as err:
print(str(err))
print_help()
exit(2)
for opt, arg in opts:
if opt == '-h':
print_help()
exit()
elif opt == '-v':
if is_windows:
archive_name = "neo4j-enterprise-%s-windows.zip" % arg
else:
archive_name = "neo4j-enterprise-%s-unix.tar.gz" % arg
archive_url = "%s/%s" % (DIST, archive_name)
elif opt == '-l':
archive_url = arg
archive_name = path.split(urlparse(archive_url).path)[-1]
stdout.write("Downloading %s...\n" % archive_url)
urlretrieve(archive_url, archive_name)
if archive_name.endswith('.zip'):
stdout.write("Unzipping %s...\n" % archive_name)
zip_ref = ZipFile(archive_name, 'r')
zip_ref.extractall(".")
zip_ref.close()
elif archive_name.endswith('.tar.gz'):
stdout.write("Unarchiving %s...\n" % archive_name)
tar_ref = TarFile(archive_name, 'r')
tar_ref.extractall(".")
tar_ref.close()
def print_help():
print(__doc__)
if __name__ == "__main__":
main()