#!/usr/bin/env python
# coding: utf-8
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import os
import posixpath
import re
import io
import errno
import logging
import subprocess
import urlparse
import argparse
from collections import OrderedDict
from ConfigParser import RawConfigParser
USAGE = """
A dependencies file should look like this:
# VCS-specific root URLs for the repositories
_root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
# File to update this script from (optional)
_self = buildtools/ensure_dependencies.py
# Check out elemhidehelper repository into extensions/elemhidehelper directory
# at tag "1.2".
extensions/elemhidehelper = elemhidehelper 1.2
# Check out buildtools repository into buildtools directory at VCS-specific
# revision IDs.
buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5
"""
SKIP_DEPENDENCY_UPDATES = os.environ.get(
"SKIP_DEPENDENCY_UPDATES", ""
).lower() not in ("", "0", "false")
class Mercurial():
def istype(self, repodir):
return os.path.exists(os.path.join(repodir, ".hg"))
def clone(self, source, target):
if not source.endswith("/"):
source += "/"
subprocess.check_call(["hg", "clone", "--quiet", "--noupdate", source, target])
def get_revision_id(self, repo, rev=None):
command = ["hg", "id", "--repository", repo, "--id"]
if rev:
command.extend(["--rev", rev])
# Ignore stderr output and return code here: if revision lookup failed we
# should simply return an empty string.
result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
return result.strip()
def pull(self, repo):
subprocess.check_call(["hg", "pull", "--repository", repo, "--quiet"])
def update(self, repo, rev):
subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--check", "--rev", rev])
def ignore(self, target, repo):
if not self.istype(target):
config_path = os.path.join(repo, ".hg", "hgrc")
ignore_path = os.path.abspath(os.path.join(repo, ".hg", "dependencies"))
config = RawConfigParser()
config.read(config_path)
if not config.has_section("ui"):
config.add_section("ui")
config.set("ui", "ignore.dependencies", ignore_path)
with open(config_path, "w") as stream:
config.write(stream)
module = os.path.relpath(target, repo)
_ensure_line_exists(ignore_path, module)
def postprocess_url(self, url):
return url
class Git():
def istype(self, repodir):
return os.path.exists(os.path.join(repodir, ".git"))
def clone(self, source, target):
source = source.rstrip("/")
if not source.endswith(".git"):
source += ".git"
subprocess.check_call(["git", "clone", "--quiet", source, target])
def get_revision_id(self, repo, rev="HEAD"):
command = ["git", "rev-parse", "--revs-only", rev + '^{commit}']
return subprocess.check_output(command, cwd=repo).strip()
def pull(self, repo):
# Fetch tracked branches, new tags and the list of available remote branches
subprocess.check_call(["git", "fetch", "--quiet", "--all", "--tags"], cwd=repo)
# Next we need to ensure all remote branches are tracked
newly_tracked = False
remotes = subprocess.check_output(["git", "branch", "--remotes"], cwd=repo)
for match in re.finditer(r"^\s*(origin/(\S+))$", remotes, re.M):
remote, local = match.groups()
with open(os.devnull, "wb") as devnull:
if subprocess.call(["git", "branch", "--track", local, remote],
cwd=repo, stdout=devnull, stderr=devnull) == 0:
newly_tracked = True
# Finally fetch any newly tracked remote branches
if newly_tracked:
subprocess.check_call(["git", "fetch", "--quiet", "origin"], cwd=repo)
def update(self, repo, rev):
subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
def ignore(self, target, repo):
module = os.path.relpath(target, repo)
exclude_file = os.path.join(repo, ".git", "info", "exclude")
_ensure_line_exists(exclude_file, module)
def postprocess_url(self, url):
# Handle alternative syntax of SSH URLS
if "@" in url and ":" in url and not urlparse.urlsplit(url).scheme:
return "ssh://" + url.replace(":", "/", 1)
return url
repo_types = OrderedDict((
("hg", Mercurial()),
("git", Git()),
))
def parse_spec(path, line):
if "=" not in line:
logging.warning("Invalid line in file %s: %s" % (path, line))
return None, None
key, value = line.split("=", 1)
key = key.strip()
items = value.split()
if not len(items):
logging.warning("No value specified for key %s in file %s" % (key, path))
return key, None
result = OrderedDict()
if not key.startswith("_"):
result["_source"] = items.pop(0)
for item in items:
if ":" in item:
type, value = item.split(":", 1)
else:
type, value = ("*", item)
if type in result:
logging.warning("Ignoring duplicate value for type %s (key %s in file %s)" % (type, key, path))
else:
result[type] = value
return key, result
def read_deps(repodir):
result = {}
deps_path = os.path.join(repodir, "dependencies")
try:
with io.open(deps_path, "rt", encoding="utf-8") as handle:
for line in handle:
# Remove comments and whitespace
line = re.sub(r"#.*", "", line).strip()
if not line:
continue
key, spec = parse_spec(deps_path, line)
if spec:
result[key] = spec
return result
except IOError, e:
if e.errno != errno.ENOENT:
raise
return None
def safe_join(path, subpath):
# This has been inspired by Flask's safe_join() function
forbidden = {os.sep, os.altsep} - {posixpath.sep, None}
if any(sep in subpath for sep in forbidden):
raise Exception("Illegal directory separator in dependency path %s" % subpath)
normpath = posixpath.normpath(subpath)
if posixpath.isabs(normpath):
raise Exception("Dependency path %s cannot be absolute" % subpath)
if normpath == posixpath.pardir or normpath.startswith(posixpath.pardir + posixpath.sep):
raise Exception("Dependency path %s has to be inside the repository" % subpath)
return os.path.join(path, *normpath.split(posixpath.sep))
def get_repo_type(repo):
for name, repotype in repo_types.iteritems():
if repotype.istype(repo):
return name
return None
def ensure_repo(parentrepo, target, roots, sourcename):
if os.path.exists(target):
return
if SKIP_DEPENDENCY_UPDATES:
logging.warning("SKIP_DEPENDENCY_UPDATES environment variable set, "
"%s not cloned", target)
return
parenttype = get_repo_type(parentrepo)
type = None
for key in roots:
if key == parenttype or (key in repo_types and type is None):
type = key
if type is None:
raise Exception("No valid source found to create %s" % target)
postprocess_url = repo_types[type].postprocess_url
root = postprocess_url(roots[type])
sourcename = postprocess_url(sourcename)
if os.path.exists(root):
url = os.path.join(root, sourcename)
else:
url = urlparse.urljoin(root, sourcename)
logging.info("Cloning repository %s into %s" % (url, target))
repo_types[type].clone(url, target)
for repo in repo_types.itervalues():
if repo.istype(parentrepo):
repo.ignore(target, parentrepo)
def update_repo(target, revisions):
type = get_repo_type(target)
if type is None:
logging.warning("Type of repository %s unknown, skipping update" % target)
return
if type in revisions:
revision = revisions[type]
elif "*" in revisions:
revision = revisions["*"]
else:
logging.warning("No revision specified for repository %s (type %s), skipping update" % (target, type))
retu
没有合适的资源?快使用搜索试试~ 我知道了~
适用于Firefox和其他基于Gecko的浏览器的Adblock Plus扩展
共672个文件
dtd:422个
properties:135个
js:43个
需积分: 5 0 下载量 187 浏览量
2023-06-03
11:20:03
上传
评论
收藏 950KB ZIP 举报
温馨提示
适用于Firefox和其他基于Gecko的浏览器的Adblock Plus扩展
资源推荐
资源详情
资源评论
收起资源包目录
适用于Firefox和其他基于Gecko的浏览器的Adblock Plus扩展 (672个子文件)
COPYING 34KB
overlay.css 6KB
filters.css 4KB
sidebar.css 3KB
objtabs.css 2KB
sendReport.css 2KB
composer.css 2KB
subscriptionSelection.css 1KB
dependencies 227B
sendReport.dtd 16KB
sendReport.dtd 13KB
sendReport.dtd 13KB
sendReport.dtd 12KB
sendReport.dtd 12KB
sendReport.dtd 11KB
sendReport.dtd 11KB
sendReport.dtd 11KB
sendReport.dtd 11KB
sendReport.dtd 11KB
sendReport.dtd 10KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 9KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
filters.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
filters.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
sendReport.dtd 8KB
filters.dtd 7KB
sendReport.dtd 7KB
sendReport.dtd 7KB
sendReport.dtd 7KB
filters.dtd 7KB
sendReport.dtd 7KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
composer.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
filters.dtd 6KB
composer.dtd 5KB
filters.dtd 5KB
composer.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
filters.dtd 5KB
共 672 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6650
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功