コード例 #1
0
 def _browse_dir(self):
     picked, _ = QtWidgets.QFileDialog.getSaveFileName(
         self, "Pick directory", QtCore.QDir.currentPath())
     if picked:
         if os.path.exists(picked):
             error_msg(self, "This directory already exists", 'warning')
         else:
             self.directory_widget.setText(picked)
             self._directory_changed()
コード例 #2
0
    def linux_register_default(self, window):
        command = os.path.abspath(sys.argv[0])
        if not os.path.isfile(command):
            return
        dirname = tempfile.mkdtemp(prefix='reprozip_mime_')
        try:
            # Install x-reprozip mimetype
            filename = os.path.join(dirname, 'nyuvida-reprozip.xml')
            with open(filename, 'w') as fp:
                fp.write('''\
<?xml version="1.0"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-reprozip">
    <comment>ReproZip Package</comment>
    <glob pattern="*.rpz"/>
  </mime-type>
</mime-info>
''')
            subprocess.check_call(['xdg-mime', 'install', filename])
            subprocess.check_call([
                'update-mime-database',
                os.path.join(os.environ['HOME'], '.local/share/mime')
            ])

            # Install icon
            icon_dest_root = os.path.join(os.environ['HOME'],
                                          '.local/share/icons/hicolor')
            icon_dest_subdir = os.path.join(icon_dest_root, '48x48/mimetypes')
            icon_dest_file = os.path.join(icon_dest_subdir,
                                          'application-x-reprozip.png')
            icon_src = os.path.join(os.path.dirname(reprounzip_qt.__file__),
                                    'icon.png')
            if not os.path.exists(icon_dest_subdir):
                os.makedirs(icon_dest_subdir)
            shutil.copyfile(icon_src, icon_dest_file)
            subprocess.check_call(['update-icon-caches', icon_dest_root])

            # Install desktop file
            app_dir = os.path.join(os.environ['HOME'],
                                   '.local/share/applications')
            if not os.path.exists(app_dir):
                os.makedirs(app_dir)
            with open(os.path.join(app_dir, 'reprounzip.desktop'), 'w') as fp:
                fp.write('''\
[Desktop Entry]
Name=ReproUnzip
Exec={0} %f
Type=Application
MimeType=application/x-reprozip
Icon={1}
'''.format(command, icon_dest_file))
            subprocess.check_call(['update-desktop-database', app_dir])
        except (OSError, subprocess.CalledProcessError):
            error_msg(window, "Error setting default application", 'error',
                      traceback.format_exc())
        finally:
            shutil.rmtree(dirname)
コード例 #3
0
ファイル: unpack.py プロジェクト: ViDA-NYU/reprozip
 def _browse_dir(self):
     picked, _ = QtWidgets.QFileDialog.getSaveFileName(
         self, "Pick directory",
         QtCore.QDir.currentPath())
     if picked:
         if os.path.exists(picked):
             error_msg(self, "This directory already exists", 'warning')
         else:
             self.directory_widget.setText(picked)
             self._directory_changed()
コード例 #4
0
 def _run(self):
     options = self.unpacker_options.currentWidget().options()
     if options is None:
         return
     runs = sorted(i.row() for i in self.runs_widget.selectedIndexes())
     if not runs:
         error_msg(self, "No run selected", 'warning')
         return
     handle_error(
         self,
         reprounzip.run(self.directory,
                        runs=runs,
                        unpacker=self.unpacker,
                        root=ROOT.INDEX_TO_OPTION[self.root.currentIndex()],
                        **options))
コード例 #5
0
ファイル: run.py プロジェクト: ViDA-NYU/reprozip
 def _run(self):
     options = self.unpacker_options.currentWidget().options()
     if options is None:
         return
     runs = sorted(i.row() for i in self.runs_widget.selectedIndexes())
     if not runs:
         error_msg(self, "No run selected", 'warning')
         return
     record_usage(run='%d/%d' % (len(runs), self.runs_widget.count()))
     handle_error(self, reprounzip.run(
         self.directory, runs=runs,
         unpacker=self.unpacker,
         root=ROOT.INDEX_TO_OPTION[self.root.currentIndex()],
         jupyter=self.run_jupyter_notebook.isChecked(),
         **options))
コード例 #6
0
ファイル: run.py プロジェクト: lcw/reprozip
 def _run(self):
     options = self.unpacker_options.currentWidget().options()
     if options is None:
         return
     runs = sorted(i.row() for i in self.runs_widget.selectedIndexes())
     if not runs:
         error_msg(self, "No run selected", 'warning')
         return
     record_usage(run='%d/%d' % (len(runs), self.runs_widget.count()))
     handle_error(
         self,
         reprounzip.run(self.directory,
                        runs=runs,
                        unpacker=self.unpacker,
                        root=ROOT.INDEX_TO_OPTION[self.root.currentIndex()],
                        jupyter=self.run_jupyter_notebook.isChecked(),
                        **options))
コード例 #7
0
ファイル: unpack.py プロジェクト: kyleam/reprozip
 def _unpack(self):
     directory = self.directory_widget.text()
     if not directory:
         return
     unpacker = self.unpackers.checkedButton()
     if unpacker:
         options = self.unpacker_options.currentWidget().options()
         if options is None:
             return
         if handle_error(
                 self,
                 reprounzip.unpack(self.package_widget.text(),
                                   unpacker.text(), directory, options)):
             self.unpacked.emit(os.path.abspath(directory),
                                options.get('root'))
     else:
         error_msg(self, "No unpacker selected", 'warning')
コード例 #8
0
ファイル: unpack.py プロジェクト: ViDA-NYU/reprozip
 def _unpack(self):
     directory = self.directory_widget.text()
     if not directory:
         return
     unpacker = self.unpackers.checkedButton()
     if unpacker:
         record_usage(unpacker=unpacker.text())
         options = self.unpacker_options.currentWidget().options()
         if options is None:
             return
         if handle_error(self, reprounzip.unpack(
                 self.package_widget.text(),
                 unpacker.unpacker,
                 directory,
                 options)):
             self.unpacked.emit(os.path.abspath(directory),
                                options.get('root'))
     else:
         error_msg(self, "No unpacker selected", 'warning')
コード例 #9
0
    def options(self):
        options = super(DockerOptions, self).options()

        if self.tunneled_x11.isChecked():
            options['args'].append('--tunneled-x11')

        if self.detach.isChecked():
            options['args'].append('--detach')

        for opt in self.raw_options.text().split():
            opt = opt.strip()
            if opt:
                options['args'].append('--docker-option=%s' % opt)

        for port in self.ports.text().split():
            port = port.strip()
            if port:
                m = self._port_re.match(port)
                if m is None:
                    error_msg(self, "Invalid port specification: '%s'" % port,
                              'warning')
                    return None
                else:
                    host, container, proto = m.groups()
                    if not host:
                        host = container
                    if proto:
                        proto = '/' + proto
                    else:
                        proto = ''
                    options['args'].extend([
                        '--docker-option=-p',
                        '--docker-option=%s:%s%s' % (host, container, proto)
                    ])

        return options
コード例 #10
0
ファイル: __init__.py プロジェクト: ViDA-NYU/reprozip
    def linux_register_default(self, window):
        record_usage(appregister='yes')
        command = os.path.abspath(sys.argv[0])
        if not os.path.isfile(command):
            logger.error("Couldn't find argv[0] location!")
            return
        dirname = tempfile.mkdtemp(prefix='reprozip_mime_')
        try:
            # Install x-reprozip mimetype
            logger.info("Installing application/x-reprozip mimetype for .rpz")
            filename = os.path.join(dirname, 'nyuvida-reprozip.xml')
            with open(filename, 'w') as fp:
                fp.write('''\
<?xml version="1.0"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-reprozip">
    <comment>ReproZip Package</comment>
    <glob pattern="*.rpz"/>
  </mime-type>
</mime-info>
''')
            subprocess.check_call(['xdg-mime', 'install', filename])
            subprocess.check_call(['update-mime-database',
                                   os.path.join(os.environ['HOME'],
                                                '.local/share/mime')])

            # Install icon
            logger.info("Copying icon")
            icon_dest_root = os.path.join(os.environ['HOME'],
                                          '.local/share/icons/hicolor')
            icon_dest_subdir = os.path.join(icon_dest_root, '48x48/mimetypes')
            icon_dest_file = os.path.join(icon_dest_subdir,
                                          'application-x-reprozip.png')
            icon_src = os.path.join(os.path.dirname(reprounzip_qt.__file__),
                                    'icon.png')
            if not os.path.exists(icon_dest_subdir):
                os.makedirs(icon_dest_subdir)
            shutil.copyfile(icon_src, icon_dest_file)
            subprocess.check_call(['update-icon-caches', icon_dest_root])

            # Install desktop file
            logger.info("Installing reprounzip.desktop file")
            app_dir = os.path.join(os.environ['HOME'],
                                   '.local/share/applications')
            if not os.path.exists(app_dir):
                os.makedirs(app_dir)
            with open(os.path.join(app_dir, 'reprounzip.desktop'), 'w') as fp:
                fp.write('''\
[Desktop Entry]
Name=ReproUnzip
Exec={0} %f
Type=Application
MimeType=application/x-reprozip
Icon={1}
'''.format(command, icon_dest_file))
            subprocess.check_call(['update-desktop-database', app_dir])

            logger.info("Application registered!")
        except (OSError, subprocess.CalledProcessError):
            error_msg(window, "Error setting default application",
                      'error', traceback.format_exc())
        finally:
            shutil.rmtree(dirname)