forked from laeg/neokit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneoget.py
122 lines (101 loc) · 3.79 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
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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Copyright (c) 2002-2016 "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 enterprise version
-n neo4j-version: download this neo4j enterprise nightly 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
neoget.py -n 3.0
"""
from __future__ import print_function
from urllib import urlretrieve
from sys import argv, stdout, exit
import getopt
from os import path, name
from zipfile import ZipFile
from tarfile import TarFile
from urlparse import urlparse
DIST = "http://dist.neo4j.org"
NIGHTLY_DIST = "http://alpha.neohq.net/dist"
NIGHTLY30_UNIX_URL = "http://alpha.neohq.net/dist/neo4j-enterprise-3.0-NIGHTLY-unix.tar.gz"
NIGHTLY30_WIN_URL = "http://alpha.neohq.net/dist/neo4j-enterprise-3.0-NIGHTLY-windows.zip"
is_windows = (name == 'nt')
def main():
try:
opts, args = getopt.getopt(argv[1:], "hv:s:l:")
except getopt.GetoptError as err:
print(str(err))
print_help()
exit()
archive_url, archive_name = neo4j_default_archive()
for opt, arg in opts:
if opt == '-h':
print_help()
exit()
elif opt in ('-v', '-n', '-l'):
archive_url, archive_name = neo4j_archive(opt, arg)
try:
download(archive_url, archive_name)
finally:
ret = 0 if path.exists(archive_name) else 1
exit(ret)
def neo4j_default_archive():
archive_url = NIGHTLY30_WIN_URL if is_windows else NIGHTLY30_UNIX_URL
archive_name = path.split(urlparse(archive_url).path)[-1]
return archive_url, archive_name
def neo4j_archive(opt, arg):
archive_url, archive_name = '', ''
if 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 == '-n':
if is_windows:
archive_name = "neo4j-enterprise-%s-NIGHTLY-windows.zip" % arg
else:
archive_name = "neo4j-enterprise-%s-NIGHTLY-unix.tar.gz" % arg
archive_url = "%s/%s" % (NIGHTLY_DIST, archive_name)
elif opt == '-l':
archive_url = arg
archive_name = path.split(urlparse(archive_url).path)[-1]
return archive_url, archive_name
def download(archive_url, archive_name, extract_to_path='.'):
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(extract_to_path)
zip_ref.close()
elif archive_name.endswith('.tar.gz'):
stdout.write("Unarchiving %s...\n" % archive_name)
tar_ref = TarFile.open(archive_name)
tar_ref.extractall(extract_to_path)
untar_folder=tar_ref.getnames()[0]
tar_ref.close()
return untar_folder
def print_help():
print(__doc__)
if __name__ == "__main__":
main()