forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinspecttarball.py
135 lines (111 loc) · 4 KB
/
inspecttarball.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
# ####################################################################
# gofed - set of tools to automize packaging of golang devel codes
# Copyright (C) 2014 Jan Chaloupka, jchaloup@redhat.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# ####################################################################
import os
import optparse
from modules.GoSymbolsExtractor import GoSymbolsExtractor
from modules.Config import Config
if __name__ == "__main__":
parser = optparse.OptionParser("%prog [-p] [-d] [-t] [directory]")
parser.add_option_group( optparse.OptionGroup(parser, "directory", "Directory to inspect. If empty, current directory is used.") )
parser.add_option(
"", "-p", "--provides", dest="provides", action = "store_true", default = False,
help = "Display all directories with *.go files"
)
parser.add_option(
"", "", "--prefix", dest="prefix", default = "",
help = "Prefix all provided import paths, used with -p option"
)
parser.add_option(
"", "-s", "--spec", dest="spec", action="store_true", default = "",
help = "If set with -p options, print list of provided paths in spec file format."
)
parser.add_option(
"", "-d", "--dirs", dest="dirs", action = "store_true", default = False,
help = "Display all direct directories"
)
parser.add_option(
"", "-t", "--test", dest="test", action = "store_true", default = False,
help = "Display all directories containing *.go test files"
)
parser.add_option(
"", "", "--scan-all-dirs", dest="scanalldirs", action = "store_true", default = False,
help = "Scan all dirs, including Godeps directory"
)
parser.add_option(
"", "", "--skip-dirs", dest="skipdirs", default = "",
help = "Scan all dirs except specified via SKIPDIRS. Directories are comma separated list."
)
options, args = parser.parse_args()
path = "."
if len(args):
path = args[0]
if not options.scanalldirs:
noGodeps = Config().getSkippedDirectories()
else:
noGodeps = []
if options.skipdirs:
for dir in options.skipdirs.split(','):
dir = dir.strip()
if dir == "":
continue
noGodeps.append(dir)
gse_obj = GoSymbolsExtractor(path, noGodeps=noGodeps)
if not gse_obj.extract():
print gse_obj.getError()
exit(1)
if options.provides:
ip = gse_obj.getSymbolsPosition()
ips = []
for pkg in ip:
ips.append(ip[pkg])
skipped_provides_with_prefix = Config().getSkippedProvidesWithPrefix()
for ip in sorted(ips):
skip = False
for prefix in skipped_provides_with_prefix:
if ip.startswith(prefix):
skip = True
break
if skip:
continue
if options.spec != "":
if ip != ".":
print "Provides: golang(%%{import_path}/%s) = %%{version}-%%{release}" % (ip)
else:
print "Provides: golang(%{import_path}) = %{version}-%{release}"
elif options.prefix != "":
if ip != ".":
print "%s/%s" % (options.prefix, ip)
else:
print options.prefix
else:
print ip
elif options.test:
sdirs = sorted(gse_obj.getTestDirectories())
for dir in sdirs:
print dir
elif options.dirs:
dirs = gse_obj.getSymbolsPosition().values() + gse_obj.getTestDirectories()
sdirs = []
for dir in dirs:
sdirs.append( dir.split("/")[0] )
sdirs = sorted(list(set(sdirs)))
for dir in sdirs:
print dir
else:
print "Usage: prog [-p] [-d] [-t] [directory]"