def close(self, abandon=False, refresh_index=True): """Ends an in-flight transaction. Returns a tuple containing a package fmri (if applicable) and the final state of the related package. If 'abandon' is omitted or False, the package will be published; otherwise the server will discard the current transaction and its related data. If 'refresh_index' is True, the repository will be instructed to update its search indices after publishing. Has no effect if 'abandon' is True.""" op = "close" if abandon: op = "abandon" headers = {} if not refresh_index: # The default is to do so, so only send this if false. headers["X-IPkg-Refresh-Index"] = 0 try: c, v = versioned_urlopen(self.origin_url, op, [0], self.trans_id, headers=headers) except (httplib.BadStatusLine, RuntimeError), e: status = httplib.INTERNAL_SERVER_ERROR msg = str(e)
def cmp_repo_version(repo1_url, repo2_url): repo1 = urlparse(repo1_url) repo2 = urlparse(repo2_url) repo_version = [] if (repo1[0] == 'http' or repo1[0] == 'https') and (repo2[0] == 'http' or repo2[0] == 'https'): for repo in (repo1_url, repo2_url): try: response, version = versioned_urlopen(repo, "versions", [0]) except URLError, e: if hasattr(e, 'reason'): print 'We failed to reach the repo server ', repo print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The repo server %s couldn\'t fulfill the request.' % repo print 'Error code: ', e.code sys.exit(1) else: version = response.readline() repo_version.append(version.lstrip('pkg-server ').rstrip('\n')) if version.startswith('pkg-server '): if repo_version[0] == repo_version[1]: print "\nRepositories are running on same version (%s) of pkg(5) software." % repo_version[ 0] else: print "\nRepositories are running on different version of pkg(5) software." print "Repository '%s' version =%s" % (repo1_url, repo_version[0]) print "Repository '%s' version =%s" % (repo2_url, repo_version[1])
def add(self, action): """Adds an action and its related content to an in-flight transaction. Returns nothing.""" attrs = action.attrs if action.data != None: datastream = action.data() # XXX Need to handle large files better; # versioned_urlopen requires the whole file to be in # memory because of the underlying request library. data = datastream.read() sz = int(attrs["pkg.size"]) else: data = "" sz = 0 headers = dict( ("X-IPkg-SetAttr%s" % i, "%s=%s" % (k, attrs[k])) for i, k in enumerate(attrs) ) headers["Content-Length"] = sz try: c, v = versioned_urlopen(self.origin_url, "add", [0], "%s/%s" % (self.trans_id, action.name), data=data, headers=headers) except (httplib.BadStatusLine, RuntimeError), e: status = httplib.INTERNAL_SERVER_ERROR msg = str(e)
def cmp_repo_version(repo1_url, repo2_url): repo1 = urlparse(repo1_url) repo2 = urlparse(repo2_url) repo_version = [] if (repo1[0] == 'http' or repo1[0] == 'https') and (repo2[0] == 'http' or repo2[0] == 'https'): for repo in (repo1_url, repo2_url): try: response, version = versioned_urlopen(repo, "versions", [0]) except URLError, e: if hasattr(e, 'reason'): print 'We failed to reach the repo server ',repo print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The repo server %s couldn\'t fulfill the request.'%repo print 'Error code: ', e.code sys.exit(1) else: version = response.readline() repo_version.append(version.lstrip('pkg-server ').rstrip('\n')) if version.startswith('pkg-server '): if repo_version[0] == repo_version[1]: print "\nRepositories are running on same version (%s) of pkg(5) software."%repo_version[0] else: print "\nRepositories are running on different version of pkg(5) software." print "Repository '%s' version =%s"%(repo1_url , repo_version[0]) print "Repository '%s' version =%s"%(repo2_url , repo_version[1])
def __network_ping(self): try: c, v = versioned_urlopen(self.get_depot_url(), "versions", [0]) except urllib2.HTTPError, e: # Server returns NOT_MODIFIED if catalog is up # to date if e.code == httplib.NOT_MODIFIED: return True else: return False
def __network_ping(self): try: c, v = versioned_urlopen(self.get_depot_url(), "catalog", [0]) except urllib2.HTTPError, e: # Server returns NOT_MODIFIED if catalog is up # to date if e.code == httplib.NOT_MODIFIED: return True else: return False
def ping_repo(url): try: c, v = versioned_urlopen(url, "catalog", [0]) except urllib2.HTTPError, e: # Server returns NOT_MODIFIED if catalog is up # to date if e.code == httplib.NOT_MODIFIED: return True else: print >> sys.stderr, "unable to access repository catalog:", e return False
def get_catalog(repo_url): repo = urlparse(repo_url) if repo[0] == "http" or repo[0] == "https": try: response, version = versioned_urlopen(repo_url, "catalog", [0]) except URLError, e: if hasattr(e, "reason"): print "Failed to reach the repo server ", repo_url print "Reason: ", e.reason elif hasattr(e, "code"): print "The repo server %s couldn't fulfill the request." % repo_url print "Error code: ", e.code sys.exit(1) except Exception, e: print e sys.exit(1)
def get_catalog(repo_url): repo = urlparse(repo_url) if repo[0] == 'http' or repo[0] == 'https': try: response, version = versioned_urlopen(repo_url, "catalog", [0]) except URLError, e: if hasattr(e, 'reason'): print 'Failed to reach the repo server ',repo_url print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The repo server %s couldn\'t fulfill the request.'%repo_url print 'Error code: ', e.code sys.exit(1) else: catalog = response.read() catalog = [val for val in catalog.split('\n') if val.startswith('V')]
def get_catalog(repo_url): repo = urlparse(repo_url) if repo[0] == 'http' or repo[0] == 'https': try: response, version = versioned_urlopen(repo_url, "catalog", [0]) except URLError, e: if hasattr(e, 'reason'): print 'Failed to reach the repo server ', repo_url print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The repo server %s couldn\'t fulfill the request.' % repo_url print 'Error code: ', e.code sys.exit(1) else: catalog = response.read() catalog = [ val for val in catalog.split('\n') if val.startswith('V') ]
def open(self): """Starts an in-flight transaction. Returns a URL-encoded transaction ID on success.""" # XXX This opens a Transaction, but who manages the server # connection? If we want a pipelined HTTP session (multiple # operations -- even if it's only one Transaction -- over a # single connection), then we can't call HTTPConnection.close() # here, and we shouldn't reopen the connection in add(), # close(), etc. try: headers = {"Client-Release": os_util.get_os_release()} c, v = versioned_urlopen(self.origin_url, "open", [0], urllib.quote(self.pkg_name, ""), headers=headers) self.trans_id = c.headers.get("Transaction-ID", None) except (httplib.BadStatusLine, RuntimeError), e: status = httplib.INTERNAL_SERVER_ERROR msg = str(e)
def cmp_repo_version(repo1_url, repo2_url): repo1 = urlparse(repo1_url) repo2 = urlparse(repo2_url) repo_version = [] if (repo1[0] == "http" or repo1[0] == "https") and (repo2[0] == "http" or repo2[0] == "https"): for repo in (repo1_url, repo2_url): try: response, version = versioned_urlopen(repo, "versions", [0]) except URLError, e: if hasattr(e, "reason"): print "We failed to reach the repo server ", repo print "Reason: ", e.reason elif hasattr(e, "code"): print "The repo server %s couldn't fulfill the request." % repo print "Error code: ", e.code sys.exit(1) except Exception, e: print e else: version = response.readline() repo_version.append(version.lstrip("pkg-server ").rstrip("\n"))
return repo_cache[uri] def fetch_manifest(src_uri, pfmri): """Return the manifest data for package-fmri 'fmri' from the repository at 'src_uri'.""" if src_uri.startswith("file://"): try: r = get_repo(src_uri) m = file(r.manifest(pfmri), "rb") except (EnvironmentError, repo.RepositoryError), e: abort(err=e) else: # Request manifest from repository. try: m = versioned_urlopen(src_uri, "manifest", [0], pfmri.get_url_path())[0] except Exception, e: abort(err=_("Unable to retrieve manifest %s from " "%s: %s") % (pfmri.get_url_path(), src_uri, e)) except: abort() # Read from repository, return to caller. try: mfst_str = m.read() except: abort(err=_("Error occurred while reading from: %s") % src_uri) if hasattr(m, "close"): m.close()
def fetch_manifest(src_uri, pfmri): """Return the manifest data for package-fmri 'fmri' from the repository at 'src_uri'.""" if src_uri.startswith("file://"): try: r = get_repo(src_uri) m = file(r.manifest(pfmri), "rb") except (EnvironmentError, repo.RepositoryError), e: abort(err=e) else: # Request manifest from repository. try: m = versioned_urlopen(src_uri, "manifest", [0], pfmri.get_url_path())[0] except Exception, e: abort(err=_("Unable to retrieve manifest %s from " "%s: %s") % (pfmri.get_url_path(), src_uri, e)) except: abort() # Read from repository, return to caller. try: mfst_str = m.read() except: abort(err=_("Error occurred while reading from: %s") % src_uri) if hasattr(m, "close"): m.close() return mfst_str