-
Notifications
You must be signed in to change notification settings - Fork 0
/
oar.py
160 lines (137 loc) · 4.49 KB
/
oar.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os
import config
import logging
import archive
class Oar:
def __init__(self, username, name):
self.name = name
self.username = username
self.path = '/home/' + username + '/opensimulator/oar/' + self.name + '.oar'
self.url = ''
# get infos
def load(self):
logging.main_logger.debug("[oar] 'load' called")
# build path and url
self.path = '/home/' + self.username + '/opensimulator/oar/' + self.name + '.oar'
self.url = archive.create_archive_url(self.path)
# check if file exists
if not os.path.isfile(self.path):
logging.main_logger.warning("[oar] oar not found : %s" % (self.path))
return False
# no error
return True
# delete oar
def delete(self):
logging.main_logger.debug("[oar] 'delete' called")
# check if file exists
if os.path.isfile(self.path):
os.remove(self.path)
self.load()
logging.main_logger.debug("[oar] oar deleted")
return True
logging.main_logger.warning("[oar] oar not found : %s" % (self.path))
return False
# load oar
'''
load oar [--merge] [--skip-assets] [<OAR path>]
params are in a dict as :
merge = False
skip_assets = False
diplacement = ""
force_terrain = False
force_parcels = False
rotation = ""
rotation_center = ""
no_objects = False
'''
def os_load_oar(self, sim_path, params={}):
logging.main_logger.debug("[oar] 'os_load_oar' called")
# check if the file exists
if not os.path.isfile(self.path):
logging.main_logger.warning("[oar] oar not found : %s" % (self.path))
return False
# check if the sim exists
if not os.path.isdir(sim_path):
logging.main_logger.warning("[oar] no sim path : %s" % (sim_path))
return False
command = 'load oar'
# add params
if 'merge' in params and params['merge']:
command += " --merge"
if 'skip_assets' in params and params['skip_assets']:
command += " --skip-assets"
if 'diplacement' in params and params['diplacement']:
command += " --diplacement"
if 'force_terrain' in params and params['force_terrain']:
command += " --force-terrain"
if 'force_parcels' in params and params['force_parcels']:
command += " --force-parcels"
if 'rotation' in params and params['rotation']:
command += " --rotation"
if 'rotation_center' in params and params['rotation_center']:
command += " --rotation-center"
if 'no_objects' in params and params['no_objects']:
command += " --no-objects"
command += ' ' + self.path
# send the command to the console
import subprocessor
sub = subprocessor.main([
self.username,
os.path.dirname(os.path.realpath(__file__)),
"python",
"send_command.py",
sim_path,
command
])
return True
# save oar
'''
save oar [-h|--home=<url>] [--noassets] [--publish] [--perm=<permissions>] [--all] [<OAR path>]
params are in a dict as :
home = ''
noassets = False
publish = False
perm = ''
all_regions = False
'''
def os_save_oar(self, sim_path, params={}):
logging.main_logger.debug("[oar] 'os_save_oar' called")
# check the name
if self.name == '':
logging.main_logger.warning("[oar] no oar name defined")
return False
# check the sim path
if not os.path.isdir(sim_path):
logging.main_logger.warning("[oar] no sim path")
return False
# check if the folder is writable
if not os.access('/home/' + self.username + '/opensimulator/oar/', os.W_OK):
logging.main_logger.warning("[oar] folder not writable : %s" % ('/home/' + self.username + '/opensimulator/oar/'))
return False
command = 'save oar'
# add the params
if 'noassets' in params and params['noassets']:
command += ' --noassets'
if 'publish' in params and params['publish']:
command += ' --publish'
if 'perm' in params and params['perm'] != '':
command += ' --perm=' + params['perm']
if 'all_regions' in params and params['all_regions']:
command += ' --all'
self.name = os.path.basename(sim_path)[:-4]
from time import strftime
self.name += '-' + strftime("%y%m%d-%H%M")
self.path = '/home/' + self.username + '/opensimulator/oar/' + self.name + '.oar'
command += ' ' + self.path
# send the command to the console
import subprocessor
sub = subprocessor.main([
self.username,
os.path.dirname(os.path.realpath(__file__)),
"python",
"send_command.py",
sim_path,
command
])
self.load()
return True