-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscript_runner
More file actions
executable file
·120 lines (99 loc) · 4.2 KB
/
script_runner
File metadata and controls
executable file
·120 lines (99 loc) · 4.2 KB
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
#!/usr/bin/env python
import os, sys
from os import walk
import os.path
import subprocess
import logging
script_dir = os.path.dirname(os.path.realpath(__file__))
lib_dir = '%s/lib' % script_dir
#sys.argv.append("--cm-managed")
if 'NO_CM' in os.environ.keys():
if 'HUE_CONF_DIR' in os.environ.keys():
if not 'HUE_CONF_DIR_ORIG' in os.environ.keys():
os.environ['HUE_CONF_DIR_ORIG'] = os.environ.get('HUE_CONF_DIR')
if not os.path.isdir(lib_dir):
print("The lib directory is missing. Please download the entire package and not just the script_runner file")
print("git clone https://github.com/cmconner156/hue_scripts.git /opt/hue_scripts")
print("or")
print("cd /opt && rm -Rf hue_scripts && wget https://github.com/cmconner156/hue_scripts/archive/master.zip && unzip master.zip && mv hue_scripts-master hue_scripts && rm -f master.zip")
exit(1)
if not os.environ["USER"] == "root":
print("This script must be run as root")
sys.exit(1)
sys.path.insert(0, lib_dir)
try:
from cm_environment import set_cm_environment, reload_with_cm_env
except ImportError as e:
print("Unable to load cm_environment please send following to support:")
print("sys.path: %s" % sys.path)
print("All files in script_dir: %s" % script_dir)
files = []
for (dirpath, dirnames, filenames) in walk(script_dir):
for file in filenames:
if file == "script_runner" or "lib" in dirpath:
print("%s/%s" % (dirpath, file))
files.append(file)
exit(1)
hue_config = set_cm_environment()
hue_path = hue_config['hue_path']
hue_bin_dir = hue_config['hue_bin_dir']
HUE_CONF_DIR = hue_config['HUE_CONF_DIR']
parcel_dir = hue_config['parcel_dir']
parcel_name = hue_config['parcel_name']
if not "SKIP_RELOAD" in os.environ.keys():
reload_with_cm_env()
if 'NO_CM' in os.environ.keys():
if 'HUE_CONF_DIR_ORIG' in os.environ.keys():
HUE_CONF_DIR = os.environ.get('HUE_CONF_DIR_ORIG')
os.environ['HUE_CONF_DIR'] = HUE_CONF_DIR
activate_file = hue_bin_dir + "/activate_this.py"
hue_bin = hue_bin_dir + "/hue"
import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(activate_file)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del activate_this
with open(hue_bin, 'rU') as f:
for line in f:
if "__requires__" in line:
desktop_ver = line.split("'")
__requires__ = desktop_ver[1]
import sys
from pkg_resources import load_entry_point
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'desktop.settings')
from custom_commands.settings import *
settings.INSTALLED_APPS.append('custom_commands')
from desktop.conf import DATABASE as desktop_database
logging.info("Using the following config make sure it looks correct")
try:
import platform
logging.info("Python Version: %s" % platform.python_version())
logging.info("OS Version: %s %s" % (platform.linux_distribution()[0], platform.linux_distribution()[1]))
except:
pass
logging.info("HUE_CONF_DIR: %s" % HUE_CONF_DIR)
logging.info("parcel_dir: %s" % parcel_dir)
logging.info("parcel_name: %s" % parcel_name)
logging.info("hue_bin_dir: %s" % hue_bin_dir)
logging.info("DB Engine: %s" % desktop_database.ENGINE.get())
logging.info("DB Name: %s" % desktop_database.NAME.get())
logging.info("DB User: %s" % desktop_database.USER.get())
logging.info("DB Host: %s" % desktop_database.HOST.get())
logging.info("DB Port: %s" % str(desktop_database.PORT.get()))
if hue_config['LD_LIBRARY_PATH'] is not None:
logging.info("LD_LIBRARY_PATH: %s" % hue_config["LD_LIBRARY_PATH"])
if __name__ == '__main__':
# sys.argv.remove("--cm-managed")
try:
sys.exit(
load_entry_point('desktop', 'console_scripts', 'hue')()
)
except UnboundLocalError, e:
logging.info("Command failed because of bug in older versions of CDH: %s" % e)
logging.info("Patching and re-running")
patch_file = "%s/patches/fix_cm_config_file.patch" % script_dir
patch_cmd = ["patch", "-p1"]
patch_file_in = open(patch_file)
os.chdir(hue_path)
subprocess.call(patch_cmd, stdin=patch_file_in)
os.chdir(script_dir)
sys.exit(
load_entry_point('desktop', 'console_scripts', 'hue')()
)