|
@@ -110,11 +110,13 @@ from grass.script import core as grass
|
|
|
# temp dir
|
|
|
remove_tmpdir = True
|
|
|
|
|
|
+# check requirements
|
|
|
def check():
|
|
|
for prog in ('svn', 'make', 'gcc'):
|
|
|
if not grass.find_program(prog, ['--help']):
|
|
|
grass.fatal(_("'%s' required. Please install '%s' first.") % (prog, prog))
|
|
|
|
|
|
+# expand prefix to class name
|
|
|
def expand_module_class_name(c):
|
|
|
name = { 'd' : 'display',
|
|
|
'db' : 'database',
|
|
@@ -134,6 +136,7 @@ def expand_module_class_name(c):
|
|
|
|
|
|
return c
|
|
|
|
|
|
+# list modules (read XML file from grass.osgeo.org/addons)
|
|
|
def list_available_modules():
|
|
|
mlist = list()
|
|
|
|
|
@@ -165,19 +168,21 @@ def list_available_modules():
|
|
|
|
|
|
return mlist
|
|
|
|
|
|
+# list modules (scan SVN repo)
|
|
|
def list_available_modules_svn():
|
|
|
mlist = list()
|
|
|
grass.message(_('Fetching list of modules from GRASS-Addons SVN (be patient)...'))
|
|
|
pattern = re.compile(r'(<li><a href=".+">)(.+)(</a></li>)', re.IGNORECASE)
|
|
|
- i = 0
|
|
|
+
|
|
|
+ if flags['c']:
|
|
|
+ grass.warning(_("Flag 'c' ignored, metadata file not available"))
|
|
|
+ if flags['g']:
|
|
|
+ grass.warning(_("Flag 'g' ignored, metadata file not available"))
|
|
|
+
|
|
|
prefix = ['d', 'db', 'g', 'i', 'm', 'ps',
|
|
|
'p', 'r', 'r3', 's', 'v']
|
|
|
nprefix = len(prefix)
|
|
|
for d in prefix:
|
|
|
- if flags['g']:
|
|
|
- grass.percent(i, nprefix, 1)
|
|
|
- i += 1
|
|
|
-
|
|
|
modclass = expand_module_class_name(d)
|
|
|
grass.verbose(_("Checking for '%s' modules...") % modclass)
|
|
|
|
|
@@ -196,16 +201,14 @@ def list_available_modules_svn():
|
|
|
continue
|
|
|
name = sline.group(2).rstrip('/')
|
|
|
if name.split('.', 1)[0] == d:
|
|
|
- print_module_desc(name, url)
|
|
|
+ print name
|
|
|
mlist.append(name)
|
|
|
|
|
|
mlist += list_wxgui_extensions()
|
|
|
-
|
|
|
- if flags['g']:
|
|
|
- grass.percent(1, 1, 1)
|
|
|
-
|
|
|
+
|
|
|
return mlist
|
|
|
|
|
|
+# list wxGUI extensions
|
|
|
def list_wxgui_extensions(print_module = True):
|
|
|
mlist = list()
|
|
|
grass.debug('Fetching list of wxGUI extensions from GRASS-Addons SVN (be patient)...')
|
|
@@ -227,116 +230,19 @@ def list_wxgui_extensions(print_module = True):
|
|
|
name = sline.group(2).rstrip('/')
|
|
|
if name not in ('..', 'Makefile'):
|
|
|
if print_module:
|
|
|
- print_module_desc(name, url)
|
|
|
+ print name
|
|
|
mlist.append(name)
|
|
|
|
|
|
return mlist
|
|
|
|
|
|
-def print_module_desc(name, url):
|
|
|
- if not flags['c'] and not flags['g']:
|
|
|
- print name
|
|
|
- return
|
|
|
-
|
|
|
- if flags['g']:
|
|
|
- print 'name=' + name
|
|
|
-
|
|
|
- # check main.c first
|
|
|
- desc = get_module_desc(url + '/' + name + '/' + name)
|
|
|
- if not desc:
|
|
|
- desc = get_module_desc(url + '/' + name + '/main.c', script = False)
|
|
|
- if not desc:
|
|
|
- if not flags['g']:
|
|
|
- print name + ' - '
|
|
|
- return
|
|
|
-
|
|
|
- if flags['g']:
|
|
|
- print 'description=' + desc.get('description', '')
|
|
|
- print 'keywords=' + ','.join(desc.get('keywords', list()))
|
|
|
- else:
|
|
|
- print name + ' - ' + desc.get('description', '')
|
|
|
-
|
|
|
-def get_module_desc(url, script = True):
|
|
|
- grass.debug('url=%s' % url)
|
|
|
- try:
|
|
|
- f = urlopen(url)
|
|
|
- except HTTPError:
|
|
|
- return {}
|
|
|
-
|
|
|
- if script:
|
|
|
- ret = get_module_script(f)
|
|
|
- else:
|
|
|
- ret = get_module_main(f)
|
|
|
-
|
|
|
- return ret
|
|
|
-
|
|
|
-def get_module_main(f):
|
|
|
- if not f:
|
|
|
- return dict()
|
|
|
-
|
|
|
- ret = { 'keyword' : list() }
|
|
|
-
|
|
|
- pattern = re.compile(r'(module.*->)(.+)(=)(.*)', re.IGNORECASE)
|
|
|
- keyword = re.compile(r'(G_add_keyword\()(.+)(\);)', re.IGNORECASE)
|
|
|
-
|
|
|
- key = ''
|
|
|
- value = ''
|
|
|
- for line in f.readlines():
|
|
|
- line = line.strip()
|
|
|
- find = pattern.search(line)
|
|
|
- if find:
|
|
|
- key = find.group(2).strip()
|
|
|
- line = find.group(4).strip()
|
|
|
- else:
|
|
|
- find = keyword.search(line)
|
|
|
- if find:
|
|
|
- ret['keyword'].append(find.group(2).replace('"', '').replace('_(', '').replace(')', ''))
|
|
|
- if key:
|
|
|
- value += line
|
|
|
- if line[-2:] == ');':
|
|
|
- value = value.replace('"', '').replace('_(', '').replace(');', '')
|
|
|
- if key == 'keywords':
|
|
|
- ret[key] = map(lambda x: x.strip(), value.split(','))
|
|
|
- else:
|
|
|
- ret[key] = value
|
|
|
-
|
|
|
- key = value = ''
|
|
|
-
|
|
|
- return ret
|
|
|
-
|
|
|
-def get_module_script(f):
|
|
|
- ret = dict()
|
|
|
- if not f:
|
|
|
- return ret
|
|
|
-
|
|
|
- begin = re.compile(r'#%.*module', re.IGNORECASE)
|
|
|
- end = re.compile(r'#%.*end', re.IGNORECASE)
|
|
|
- mline = None
|
|
|
- for line in f.readlines():
|
|
|
- if not mline:
|
|
|
- mline = begin.search(line)
|
|
|
- if mline:
|
|
|
- if end.search(line):
|
|
|
- break
|
|
|
- try:
|
|
|
- key, value = line.split(':', 1)
|
|
|
- key = key.replace('#%', '').strip()
|
|
|
- value = value.strip()
|
|
|
- if key == 'keywords':
|
|
|
- ret[key] = map(lambda x: x.strip(), value.split(','))
|
|
|
- else:
|
|
|
- ret[key] = value
|
|
|
- except ValueError:
|
|
|
- pass
|
|
|
-
|
|
|
- return ret
|
|
|
-
|
|
|
def cleanup():
|
|
|
if remove_tmpdir:
|
|
|
grass.try_rmdir(tmpdir)
|
|
|
else:
|
|
|
grass.message(_("Path to the source code:"))
|
|
|
sys.stderr.write('%s\n' % os.path.join(tmpdir, options['extension']))
|
|
|
-
|
|
|
+
|
|
|
+# install extension on MS Windows
|
|
|
def install_extension_win():
|
|
|
### TODO: do not use hardcoded url
|
|
|
version = grass.version()['version'].split('.')
|
|
@@ -367,6 +273,7 @@ def install_extension_win():
|
|
|
except HTTPError:
|
|
|
grass.fatal(_("GRASS Addons <%s> not found") % options['extension'])
|
|
|
|
|
|
+# install extension
|
|
|
def install_extension():
|
|
|
gisbase = os.getenv('GISBASE')
|
|
|
if not gisbase:
|
|
@@ -432,6 +339,7 @@ def install_extension():
|
|
|
grass.warning(_('This add-on module will not function until you set the '
|
|
|
'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
|
|
|
|
|
|
+# install extension on other plaforms
|
|
|
def install_extension_other():
|
|
|
gisbase = os.getenv('GISBASE')
|
|
|
gui_list = list_wxgui_extensions(print_module = False)
|
|
@@ -445,7 +353,7 @@ def install_extension_other():
|
|
|
if not flags['s']:
|
|
|
grass.fatal(_("Installation of wxGUI extension requires -%s flag.") % 's')
|
|
|
|
|
|
- grass.message(_("Fetching '%s' from GRASS-Addons SVN (be patient)...") % options['extension'])
|
|
|
+ grass.message(_("Fetching <%s> from GRASS-Addons SVN (be patient)...") % options['extension'])
|
|
|
|
|
|
os.chdir(tmpdir)
|
|
|
if grass.verbosity() == 0:
|
|
@@ -491,7 +399,7 @@ def install_extension_other():
|
|
|
|
|
|
os.chdir(os.path.join(tmpdir, options['extension']))
|
|
|
|
|
|
- grass.message(_("Compiling '%s'...") % options['extension'])
|
|
|
+ grass.message(_("Compiling <%s>...") % options['extension'])
|
|
|
if options['extension'] not in gui_list:
|
|
|
ret = grass.call(makeCmd,
|
|
|
stdout = outdev)
|
|
@@ -506,7 +414,7 @@ def install_extension_other():
|
|
|
if flags['i'] or options['extension'] in gui_list:
|
|
|
return
|
|
|
|
|
|
- grass.message(_("Installing '%s'...") % options['extension'])
|
|
|
+ grass.message(_("Installing <%s>...") % options['extension'])
|
|
|
|
|
|
ret = grass.call(installCmd,
|
|
|
stdout = outdev)
|
|
@@ -514,7 +422,7 @@ def install_extension_other():
|
|
|
if ret != 0:
|
|
|
grass.warning(_('Installation failed, sorry. Please check above error messages.'))
|
|
|
else:
|
|
|
- grass.message(_("Installation of '%s' successfully finished.") % options['extension'])
|
|
|
+ grass.message(_("Installation of <%s> successfully finished.") % options['extension'])
|
|
|
|
|
|
# manual page: fix href
|
|
|
if os.getenv('GRASS_ADDON_PATH'):
|
|
@@ -545,6 +453,7 @@ def install_extension_other():
|
|
|
grass.warning(_('This add-on module will not function until you set the '
|
|
|
'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
|
|
|
|
|
|
+# remove existing extension (reading XML file)
|
|
|
def remove_extension():
|
|
|
# try to download XML metadata file first
|
|
|
url = "http://grass.osgeo.org/addons/grass%s.xml" % grass.version()['version'].split('.')[0]
|
|
@@ -590,6 +499,7 @@ def remove_extension():
|
|
|
|
|
|
grass.message(_("Extension <%s> successfully uninstalled.") % options['extension'])
|
|
|
|
|
|
+# remove exising extension (using standard files layout)
|
|
|
def remove_extension_std():
|
|
|
# is module available?
|
|
|
if not os.path.exists(os.path.join(options['prefix'], 'bin', options['extension'])):
|
|
@@ -601,26 +511,16 @@ def remove_extension_std():
|
|
|
if os.path.isfile(file):
|
|
|
os.remove(file)
|
|
|
|
|
|
-def create_dir(path):
|
|
|
- if os.path.isdir(path):
|
|
|
- return
|
|
|
-
|
|
|
- try:
|
|
|
- os.makedirs(path)
|
|
|
- except OSError, e:
|
|
|
- grass.fatal(_("Unable to create '%s': %s") % (path, e))
|
|
|
-
|
|
|
- grass.debug("'%s' created" % path)
|
|
|
-
|
|
|
+# check links in CSS
|
|
|
def check_style_files(fil):
|
|
|
- #check the links to grassdocs.css/grass_logo.png to a correct manual page of addons
|
|
|
- dist_file = os.path.join(os.getenv('GISBASE'),'docs','html',fil)
|
|
|
- addons_file = os.path.join(options['prefix'],'docs','html',fil)
|
|
|
- #check if file already exists in the grass addons docs html path
|
|
|
+ # check the links to grassdocs.css/grass_logo.png to a correct manual page of addons
|
|
|
+ dist_file = os.path.join(os.getenv('GISBASE'), 'docs', 'html', fil)
|
|
|
+ addons_file = os.path.join(options['prefix'], 'docs', 'html', fil)
|
|
|
+ # check if file already exists in the grass addons docs html path
|
|
|
if os.path.isfile(addons_file):
|
|
|
return
|
|
|
- #otherwise copy the file from $GISBASE/docs/html, it doesn't use link
|
|
|
- #because os.symlink it work only in Linux
|
|
|
+ # otherwise copy the file from $GISBASE/docs/html, it doesn't use link
|
|
|
+ # because os.symlink it work only in Linux
|
|
|
else:
|
|
|
try:
|
|
|
shutil.copyfile(dist_file,addons_file)
|
|
@@ -628,13 +528,9 @@ def check_style_files(fil):
|
|
|
grass.fatal(_("Unable to create '%s': %s") % (addons_file, e))
|
|
|
|
|
|
def check_dirs():
|
|
|
- create_dir(os.path.join(options['prefix'], 'bin'))
|
|
|
- create_dir(os.path.join(options['prefix'], 'docs', 'html'))
|
|
|
check_style_files('grass_logo.png')
|
|
|
check_style_files('grassdocs.css')
|
|
|
- create_dir(os.path.join(options['prefix'], 'man', 'man1'))
|
|
|
- create_dir(os.path.join(options['prefix'], 'scripts'))
|
|
|
-
|
|
|
+
|
|
|
def main():
|
|
|
# check dependecies
|
|
|
if sys.platform != "win32":
|