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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""'epyd' - Command line interface for management of pydevd.py
The epyd commandline interface provides a helpers for the
preparation of remote debugging.
**SYNOPSIS**:
epyd [OPTIONS]
**OPTIONS**:
.
**epyd-options**:
--force
Force selected parameters, ignore standard constraints.
--package
Package the current 'pysrc' into a deployment archive
for remote debugging.
*REMARK*: current implementation packages the complete
'pysrc' subdirectory, which actually seems not
to be required.
--package-type=(zip|tar.gz)
Type of archive.
--package-path=<filepathname-package>
The file pathname for the package to create.
--package-print
Prints the path name of the created package to stdout.
--no-rdbg
Suppress the actual start of remote debugging when '--rdbg'
is set, just scans and reads the rdbg-options for analysis.
**rdbg-options**:
--rdbg
the remote debugging peer for this instance
--rdbg-fwd
requested state forwarding to nested subprocess levels
--rdbg-root
rootdirectory of eclipse
--rdbg-sub
sub directory of PyDev for 'pydevd.py'
**common options**:
-d --debug
Debug entries, does NOT work with 'python -O ...'.
Developer output, aimed for filtering.
-h --help
This help.
-Version --Version
Current version - detailed.
-v --verbose
Verbose.
-version --version
Current version - terse.
**ARGUMENTS**:
none.
**ENVIRONMENT**:
* PYTHON OPTIONS:
-O, -OO: Eliminates '__debug__' code.
**EXAMPLES**:
Basic calls:
* epyd --enumerate
**SEE ALSO**:
* https://pypi.python.org/pypi/epyunit/
* https://pythonhosted.org/epyunit/
**COPYRIGHT**:
Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez
Copyright (C)2015-2017 Arno-Can Uestuensoez
"""
from __future__ import absolute_import
#from __future__ import print_function
__author__ = 'Arno-Can Uestuensoez'
__license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints"
__copyright__ = "Copyright (C) 2010-2016 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez"
__version__ = '0.2.9'
__uuid__='9de52399-7752-4633-9fdc-66c87a9200b8'
__release__ = 'alpha2'
__docformat__ = "restructuredtext en"
import os, sys, platform, getopt
#
#--- early fetch of CLI options
#
# name of application, used for several filenames as default
if '--appname' in sys.argv:
_ai = sys.argv.index('--appname')
_APPNAME = sys.argv[_ai]
else:
_APPNAME = "epyd"
# runtime environment
_host = platform.node()
_user = "testuser"
_osu = platform.uname()
_os = _osu[0]
_osver = _osu[2]
_arch = _osu[-1]
_dist, _distver,_x = platform.dist()
# just to assure PYTHONPATH...
try:
from epyunit.SystemCalls import SystemCalls
from epyunit.SubprocUnit import SubprocessUnit
except Exception as e:
print "\n#\n#*** Set 'PYTHONPATH' ("+str(e)+")\n#\n"
sys.exit(1)
class EPyUnitException(Exception):
pass
def usage():
if __name__ == '__main__':
import pydoc
#FIXME: literally displayed '__main__'
print pydoc.help(__name__)
else:
help(str(os.path.basename(sys.argv[0]).split('.')[0]))
_longopts = [
#
"enumerate",
"package","package-type=","package-path=","package-print",
"force",
"no-rdbg",
# misc
"help","debug","verbose","version","Version",
]
_sopts = "hdv"
def usagemin():
print "\nAvailable options:"
slst = ""
nl = 0
print "\nshortopts:"
for s in _sopts:
if nl == 10:
print " "+slst
nl = -1
slst = ""
if s == ':':
continue
slst += "-%s "%(s)
if slst:
print " "+slst
ilst = ""
nl = 0
print "\nlongopts:"
for i in sorted(_longopts):
if nl == 2 or nl>=len(_longopts):
print " "+ilst
nl = -1
ilst = ""
ilst += "--%-20s "%(i)
nl += 1
if ilst:
print " "+ilst
print """
Examples:
epyd
"""
#
# using for now getopt, thus help here as an extra handling...
#
if "--help" in sys.argv or "-help" in sys.argv:
usage()
sys.exit()
if "-h" in sys.argv:
usagemin()
sys.exit()
#
# Remote debugging
#
# but first eliminate callers default-dir because epyunit(bin) == epyunit(pkg)
#FIXME: print "4TEST:"+str(sys.path)
#FIXME: print "4TEST:"+str(sys.argv)
_tmp = sys.path.pop(0)
import epyunit.debug.checkRDbg
_rdbgthis,_rdbg,_rdbgfwd,_rdbgroot,_rdbgsub = epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions(**{'label':_APPNAME,})
"""
pydev remote debug options:
_rdbgthis: requested debugging status for this process instance
_rdbg: the remote debugging peer for this instance
_rdbgfwd: requested state forwarding to nested subprocess levels
_rdbgroot: rootdirectory of eclipse
_rdbgsub: sub directory of PyDev for 'pydevd.py'
"""
# put it in-place again, who knows...
sys.path.insert(0,_tmp)
# activate remote debug stub call
import epyunit.debug.pydevrdc
if _rdbgthis and not '--no-rdbg' in sys.argv:
epyunit.debug.pydevrdc.PYDEVD.startDebug() # start debugging here...
#
# remote breakpoints could be set from here on...
#
pass
_kargs={}
try:
_opts, _args = getopt.getopt(sys.argv[1:], _sopts, _longopts)
except getopt.GetoptError, err:
print str(err)
usagemin()
sys.exit(2)
#
# defaults
#
# name of tested application
_appname = None
# test id, to be printed with result data records
_testid = 0
# perform hard-coded basic selftest
_selftest = False
_slang = 'python'
# verbose output
_verbose = 0
# debug output
_debug = 0
_package = False
_package_type = 'zip'
"""Package type for remote stub."""
_package_path = None
_package_print = False
_altpat = "org.python.pydev_[0-9]*.[0-9]*.[0-9]*201*/pysrc/pydevd.py"
"""Search pattern for pydevd.py"""
_force = False
for _o,_a in _opts:
#
if _o in ("--enumerate",):
pass
elif _o in ("--package",):
_package = True
elif _o in ("--package-print",):
_package_print = True
elif _o in ("--package-type",):
if _a.lower() in ('zip', 'tar.gz',):
_package_type = _a.lower()
else:
print >>sys.stderr, "ERROR:Unknown package type:"+str(_a)
sys.exit(1)
pass
elif _o in ("--package-path",):
_package_path = _a
elif _o in ("--force",):
_force = True
elif _o in ("--no-rdbg",):
_kargs['nordbg'] = True
_nordbg = 1
#
elif _o in ("-d","--debug",):
_kargs['debug'] = True
_debug += 1
elif _o in ("-v","--verbose",):
_verbose += 1
elif _o in ("--version",):
print str(__version__)
sys.exit()
elif _o in ("--Version",):
print "app: "+str(_APPNAME)
print "version: "+str(__version__)
print "author: "+str(__author__)
print "copyright:"+str(__copyright__)
print "license: "+str(__license__)
print "file: "+str(os.path.basename(__file__))
sys.exit()
else:
assert False, "unhandled option"+str(_o)
#
# normal procedure...
#
if _verbose>0:
_kargs['verbose'] = _verbose
if _debug > 0:
_kargs['debug'] = _debug
if _package:
sx = epyunit.debug.checkRDbg.scanEclipseForPydevd()
sx = os.path.dirname(sx)
if not _package_path:
_package_path = os.path.dirname(sx)
if _package_type in ('zip',):
_package_path += '.zip'
elif _package_type in ('tar.gz',):
_package_path += '.tar.gz'
if _verbose:
print "# Package path name: "+str(_package_path)
if _verbose:
print "# Package type: "+str(_package_type)
if os.path.exists(_package_path):
if _force:
if _verbose:
print "# Package exist, rewrite now."
pass
else:
print >>sys.stderr, "ERROR:Package exists:"+str(_package_path)
sys.exit(1)
import errno
from shutil import copy,copytree
def copydir(src, dest):
try:
copytree(src, dest+os.path.sep+os.path.basename(src))
except Exception as e:
# fetch contents too
if e.errno == errno.ENOTDIR:
copy(src, dest)
else:
print('ERROR:Directory not copied: %s' % e)
# prep archive
from shutil import copyfile,rmtree
_tempbuf = _package_path+'.d' + os.path.sep + os.path.basename(_package_path)
if _tempbuf.endswith('.zip'):
_tempbuf = _tempbuf[:-4]
elif _tempbuf.endswith('.tar.gz'):
_tempbuf = _tempbuf[:-7]
else:
print >>sys.stderr, "ERROR:Supports only archive types: 'zip' or 'tar.gz'"
sys.exit(1)
_pkgname_rel = os.path.basename(_tempbuf)
_tempbuf = os.path.dirname(_tempbuf)
if _force and os.path.exists(_tempbuf):
rmtree(_tempbuf)
os.mkdir(_tempbuf+os.path.sep)
os.mkdir(_tempbuf+os.path.sep+_pkgname_rel)
copydir(sx, _tempbuf+os.path.sep+_pkgname_rel)
_c = os.path.curdir
os.chdir(_tempbuf)
if _package_type in ('zip',):
from zipfile import ZipFile
with ZipFile(_package_path, 'w') as myarch:
for root, dirs, files in os.walk(_pkgname_rel):
for file in files:
myarch.write(os.path.join(root, file))
#myarch.write(_pkgname_rel)
pass
elif _package_type in ('tar.gz',):
import tarfile
tar = tarfile.open(_package_path, 'w:gz')
for root, dirs, files in os.walk(_pkgname_rel):
for file in files:
tar.add(os.path.join(root, file))
pass
tar.close()
pass
if _package_print:
print "# Output created archive: "+str(os.path.basename(_package_path))
print _package_path
else:
# sx = epyunit.debug.pydevrdc.PYDEVD.scanEclipseForPydevd(**{'altpat':_altpat,})
sx = epyunit.debug.checkRDbg.scanEclipseForPydevd(_rdbgroot, altpat=_rdbgsub)
#_rdbgthis,_rdbg,_rdbgfwd,, = epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions(**{'label':_APPNAME,})
print sx
|