-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
118 lines (91 loc) · 3.59 KB
/
Copy pathcommon.py
File metadata and controls
118 lines (91 loc) · 3.59 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
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ['TacticException', 'TacticInfo']
import cStringIO, os, sys, urllib, xmlrpclib, re, string
from xml.dom.minidom import parseString
from pyasm.application.common import BaseAppInfo
class TacticException(Exception):
pass
class TacticInfo(BaseAppInfo):
'''Holds data in application session that is fed by the tactic server.
For this implementation, the information is retrieved by get
variables from application. This information is generally fed into
the environment class'''
def get_ticket(my):
return my.app.get_var("tactic_ticket")
def get_tactic_server(my):
tactic_server = my.app.get_var("tactic_server")
return tactic_server
def get_xmlrpc_server(my):
xmlrpc_url = my.app.get_var("tactic_xmlrpc")
# Applications can't take https
#xmlrpc_url = xmlrpc_url.replace('https:', 'http:')
# can't check for None here because this fires and __eq__ function
# to the server
if not isinstance(my.xmlrpc_server, xmlrpclib.Server):
my.xmlrpc_server = xmlrpclib.Server(xmlrpc_url, allow_none=True)
# WARNING: this is changing code in the xmlrpclib library. This
# library is not sending a proper user agent. Hacking it in
# that it is a little better
if os.name == "nt":
user_agent = 'xmlrpclib.py (Windows)'
else:
user_agent = 'xmlrpclib.py (Linux)'
xmlrpclib.Transport.user_agent = user_agent
# this will be removed. as project_code should be set per call.
project_code = my.get_project_code()
if project_code:
my.xmlrpc_server.set_project(project_code)
return my.xmlrpc_server
def get_upload_server(my):
upload_url = my.app.get_var("tactic_upload")
return upload_url
def get_user(my):
user = my.app.get_var("tactic_user")
return user
def get_tmpdir(my):
tmpdir = my.app.get_var("tactic_tmpdir")
return tmpdir
def get_sandbox_dir(my):
sandbox_dir = my.app.get_var("tactic_sandbox_dir")
return sandbox_dir
def get_project_code(my):
project_code = my.app.get_var("tactic_project_code")
return project_code
def get_server(my):
base_url = my.app.get_var("tactic_base_url")
base_url = re.sub('http://|https://', '', base_url)
return base_url
# general common functions
def upload_warning():
info = TacticInfo.get()
info.report_warning('','', upload=True)
#remove the file afterwards
path = "%s/warning.txt" % info.get_tmpdir()
if os.path.exists(path):
os.unlink(path)
def explore(dir):
'''create path and open explorer'''
if not os.path.exists(dir):
os.makedirs(dir)
if os.name=='nt':
program = 'explorer'
for path in string.split(os.environ["PATH"], os.pathsep):
file = os.path.join(path, program) + ".exe"
try:
return os.spawnv(os.P_WAIT, file, (file,) + tuple(['file://%s' %dir]))
except os.error:
pass
raise os.error, "cannot find executable"
else: # mac OSX
program = '/usr/bin/open'
os.system('%s %s' %(program, dir))