2 # Copyright (C) 2008, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
5 from optparse
import OptionParser
6 import os
, sys
, tempfile
, shutil
7 from logging
import info
, debug
9 zeroinstall_dir
= os
.environ
.get('0IMPORT_ZEROINSTALL', None)
11 sys
.path
.insert(1, zeroinstall_dir
)
15 parser
= OptionParser(usage
="usage: %prog URI")
17 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
18 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
20 (options
, args
) = parser
.parse_args()
23 print "0export (zero-install) " + version
24 print "Copyright (C) 2008 Thomas Leonard"
25 print "This program comes with ABSOLUTELY NO WARRANTY,"
26 print "to the extent permitted by law."
27 print "You may redistribute copies of this program"
28 print "under the terms of the GNU General Public License."
29 print "For more information about these matters, see the file named COPYING."
34 logger
= logging
.getLogger()
35 if options
.verbose
== 1:
36 logger
.setLevel(logging
.INFO
)
38 logger
.setLevel(logging
.DEBUG
)
44 from zeroinstall
.zerostore
import manifest
45 from zeroinstall
.injector
import policy
, handler
, model
, iface_cache
46 from zeroinstall
import SafeException
48 uri
= model
.canonical_iface_uri(args
[0])
50 print "Finding versions of %s..." % uri
52 class NoLocalVersions
:
53 def meets_restriction(self
, impl
):
54 if isinstance(impl
, model
.ZeroInstallImplementation
):
56 return not (i
.startswith('/') or i
.startswith('.'))
57 # Should package impls be OK?
60 no_local
= NoLocalVersions()
62 class NoLocalRestrictions(dict):
63 # This restriction applies to all interfaces, so ignore key
64 def get(self
, key
, default
):
69 p
= policy
.Policy(uri
, h
)
71 # Don't let us choose local devel versions
72 p
.solver
.extra_restrictions
= NoLocalRestrictions()
74 solved
= p
.solve_with_downloads()
75 h
.wait_for_blocker(solved
)
78 raise SafeException("Failed to select a set of versions!")
80 for iface
, impl
in p
.solver
.selections
.items():
81 print " %s : %s" % (iface
.get_name(), impl
.get_version())
83 downloads
= p
.download_uncached_implementations()
85 print "Downloading implementations..."
86 h
.wait_for_blocker(downloads
)
88 tmp
= tempfile
.mkdtemp(prefix
= '0export-')
90 implementations
= os
.path
.join(tmp
, 'implementations')
91 for impl
in p
.solver
.selections
.values():
92 src
= p
.get_implementation_path(impl
)
93 dst
= os
.path
.join(implementations
, impl
.id)
94 shutil
.copytree(src
, dst
)
95 manifest
.verify(dst
, impl
.id)
96 for root
, dirs
, files
in os
.walk(dst
):
98 os
.unlink(os
.path
.join(dst
, '.manifest'))
101 except SafeException
, ex
:
102 print >>sys
.stderr
, str(ex
)