compile.py :  » Installer » Zero-Install » zeroinstall-injector-0.47 » zeroinstall » 0launch-gui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Installer » Zero Install 
Zero Install » zeroinstall injector 0.47 » zeroinstall » 0launch gui » compile.py
# Copyright (C) 2009, Thomas Leonard
# See the README file for details, or visit http://0install.net.

import os, subprocess
import gobject
import dialog
from logging import info

from zeroinstall.injector import reader,iface_cache,model
from zeroinstall.injector.policy import Policy
  
XMLNS_0COMPILE = 'http://zero-install.sourceforge.net/2006/namespaces/0compile'

class Command:
  def __init__(self):
    self.child = None
    self.error = ""

  def run(self, command, success):
    assert self.child is None
    self.success = success
    self.child = subprocess.Popen(command,
            stdout = subprocess.PIPE,
            stderr = subprocess.STDOUT)
    gobject.io_add_watch(self.child.stdout, gobject.IO_IN | gobject.IO_HUP, self.got_data)
  
  def got_data(self, src, cond):
    data = os.read(src.fileno(), 100)
    if data:
      self.error += data
      return True
    else:
      status = self.child.wait()
      self.child = None

      if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
        self.success()
      else:
        if os.WIFEXITED(status):
          status = os.WEXITSTATUS(status)
          if status == 1 and not self.error:
            return False # Cancelled
          dialog.alert(None, _("Command failed with exit code %(status)d:\n%(error)s\n") %
            {'status': status, 'error': self.error})
        else:
          dialog.alert(None, _("Command failed:\n%s\n") % self.error)
      return False

def compile(policy, interface, autocompile = False):
  our_min_version = '0.18'  # The oldest version of 0compile we support

  def add_feed():
    # A new local feed may have been registered, so update the interface from the cache
    info(_("0compile command completed successfully. Reloading interface details."))
    reader.update_from_cache(interface)
    policy.recalculate()

  def build():
    # Get the chosen versions
    src_policy = Policy(interface.uri, src = True)
    src_policy.freshness = 0

    src_policy.recalculate()
    if not src_policy.ready:
      raise Exception(_('Internal error: required source components not found!'))

    root_iface = iface_cache.iface_cache.get_interface(src_policy.root)
    impl = src_policy.implementation[root_iface]

    min_version = impl.metadata.get(XMLNS_0COMPILE + ' min-version', our_min_version)
    # Check the syntax is valid and the version is high enough
    if model.parse_version(min_version) < model.parse_version(our_min_version):
      min_version = our_min_version

    # Do the whole build-and-register-feed
    c = Command()
    c.run(("0launch",
      '--message', _('Download the 0compile tool, to compile the source code'),
      '--not-before=' + min_version,
      "http://0install.net/2006/interfaces/0compile.xml",
      'gui',
      '--no-prompt',
      interface.uri), add_feed)

  if autocompile:
    c = Command()
    c.run(("0launch",
      '--message', 'Download the 0compile tool, to compile the source code',
      '--not-before=' + our_min_version,
      "http://0install.net/2006/interfaces/0compile.xml",
      'autocompile',
      '--gui',
      interface.uri), add_feed)
  else:
    # Prompt user to choose source version
    c = Command()
    c.run(['0launch',
      '--message', _('Download the source code to be compiled'),
      '--gui', '--source', '--download-only', interface.uri], build)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.