~zyga/snapcraft/custom-plugin

« back to all changes in this revision

Viewing changes to snapcraft/meta.py

  • Committer: Snappy Tarmac
  • Author(s): Sergio Schvezov
  • Date: 2015-09-15 21:02:02 UTC
  • mfrom: (143.9.9 snapcraft)
  • Revision ID: snappy_tarmac-20150915210202-ir46ij16qra2fwtw
Support config by sergiusens approved by sergiusens,chipaca

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    _write_package_yaml(meta_dir, config_data, arches)
58
58
    _write_readme_md(meta_dir, config_data)
59
59
 
 
60
    if 'config' in config_data:
 
61
        _setup_config_hook(meta_dir, config_data['config'])
 
62
 
60
63
    return meta_dir
61
64
 
62
65
 
76
79
        f.write(readme_md)
77
80
 
78
81
 
 
82
def _setup_config_hook(meta_dir, config):
 
83
    hooks_dir = os.path.join(meta_dir, 'hooks')
 
84
 
 
85
    os.makedirs(hooks_dir)
 
86
 
 
87
    execparts = shlex.split(config)
 
88
    args = execparts[1:] if len(execparts) > 1 else []
 
89
 
 
90
    config_hook_path = os.path.join(hooks_dir, 'config')
 
91
    _write_wrap_exe(execparts[0], config_hook_path, args=args, cwd='$SNAP_APP_PATH')
 
92
 
 
93
 
79
94
def _copy_icon(meta_dir, icon_path):
80
95
    new_icon_path = os.path.join(meta_dir, os.path.basename(icon_path))
81
96
    shutil.copyfile(icon_path, new_icon_path)
122
137
        return ' '.join([shlex.quote(x) for x in newparts])
123
138
 
124
139
 
 
140
def _write_wrap_exe(wrapexec, wrappath, args=[], cwd=None):
 
141
    args = ' '.join(args) + ' $*' if args else '$*'
 
142
    cwd = 'cd {}'.format(cwd) if cwd else ''
 
143
 
 
144
    snap_dir = common.get_snapdir()
 
145
    assembled_env = common.assemble_env().replace(snap_dir, '$SNAP_APP_PATH')
 
146
    script = ('#!/bin/sh\n' +
 
147
              '{}\n'.format(assembled_env) +
 
148
              '{}\n'.format(cwd) +
 
149
              'exec "{}" {}\n'.format(wrapexec, args))
 
150
 
 
151
    with open(wrappath, 'w+') as f:
 
152
        f.write(script)
 
153
 
 
154
    os.chmod(wrappath, 0o755)
 
155
 
 
156
 
125
157
def _wrap_exe(relexepath):
126
158
    snap_dir = common.get_snapdir()
127
159
    exepath = os.path.join(snap_dir, relexepath)
149
181
            else:
150
182
                logger.warning('Warning: unable to find "{}" in the path'.format(relexepath))
151
183
 
152
 
    assembled_env = common.assemble_env().replace(snap_dir, '$SNAP_APP_PATH')
153
 
    script = ('#!/bin/sh\n' +
154
 
              '{}\n'.format(assembled_env) +
155
 
              'exec "{}" $*\n'.format(wrapexec))
156
 
 
157
 
    with open(wrappath, 'w+') as f:
158
 
        f.write(script)
159
 
 
160
 
    os.chmod(wrappath, 0o755)
 
184
    _write_wrap_exe(wrapexec, wrappath)
161
185
 
162
186
    return os.path.relpath(wrappath, snap_dir)
163
187