Ubuntu 环境的一些常见问题——记性不好就得写下来

用ssh登录一个机器(换过ip地址),提示输入yes后,屏幕不断出现y,只有按ctrl + c结束

 

错误是:The authenticity of host 192.168.0.xxx can't be established.

 

以前和同事碰到过这个问题,解决了,没有记录,这次又碰到了不知道怎么处理,还好有QQ聊天记录,查找到一下,找到解决方案:

 

执行ssh  -o StrictHostKeyChecking=no  192.168.0.xxx 就OK




某天机器又改IP了,ssh后,报:

mmt@FS01:~$ ssh  -o StrictHostKeyChecking=no  192.168.0.130
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
fe:d6:f8:59:03:a5:de:e8:29:ef:3b:26:6e:3d:1d:4b.
Please contact your system administrator.
Add correct host key in /home/mmt/.ssh/known_hosts to get rid of this message.
Offending key in /home/mmt/.ssh/known_hosts:38
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Permission denied (publickey,password).

 注意这句

Add correct host key in /home/mmt/.ssh/known_hosts to get rid of this message.

执行:

mv  /home/mmt/.ssh/known_hosts known_hosts.bak

再连:

ssh  -o StrictHostKeyChecking=no  192.168.0.130

o k  咯!



『小工具箱』ubuntu右键添加打开终端的快捷菜单

ubuntu上面来遇到的第一个最常用的问题就是,右键单击桌面,发现没有“打开终端”这个选项,下面介 绍两种方法来在右键添加“打开终端”这个选项。

第一种方法:

sudo apt-get install nautilus-open-terminal

安装一个包,即可在右键里面添加一个“打开终端”的菜单。

第二种方法:

进入主目录的.gnome2/nautilus- scripts目录。新建一个文件,文件名任意(这个文件名会显示在右键菜单里,最好是通俗易懂的,比如“打开终端”或“open- terminal”),文件内容如下:

#!/bin/bash

#

# This script opens a gnome-terminal in the directory you select.

#

# Distributed under the terms of GNU GPL version 2 or later

#

# Install in ~/.gnome2/nautilus-scripts or ~/Nautilus/scripts

# You need to be running Nautilus 1.0.3+ to use scripts.

# When a directory is selected, go there. Otherwise go to current

# directory. If more than one directory is selected, show error.

if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then

set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS

if [ $# -eq 1 ]; then

destination="$1"

# Go to file's directory if it's a file

if [ ! -d "$destination" ]; then

destination="`dirname "$destination"`"

fi

else

zenity --error --title="Error - Open terminal here" \

--text="You can only select one directory."

exit 1



Ubuntu12.04安装JDK之后,启动eclipse出错(路径下有LOG文件要你阅读)、、、、、、、


解决办法:64位的话在终端运行:

ln-s/usr/libjni/libswt-*~/.swt/lib/Linux/x86-64/



32位的话:ln-s/usr/lib/jni/libswt-*~/.swt/lib/linux/x86



adb_use

android adb命令行工具使用

1.启动和关闭ADB服务(adb start-server和adb kill-server)

    经作者测试,模拟器在运行一段时间后,adb服务有可能(在Windows进程中可找到这个服务,该服务用来为模拟器或通过USB数据线连接的真机服务) 会出现异常。这时需要重新对adb服务关闭和重启。当然,重启Eclipse可能会解决问题。但那比较麻烦。如果想手工关闭adb服务,可以使用下面的命 令。
  adb kill-server
  在关闭adb服务后,要使用如下的命令启动adb服务。
  adb start-server
  2 查询当前模拟器/设备的实例(adb devices)

    有时需要启动多个模拟器实例,或启动模拟器的同时通过USB数据线连接了真机。在这种情况下就需要使用如下的命令查询当前有多少模拟器或真机在线。
  adb devices
如果在运行Android程序时有多个模拟器或真机在线,那么会出现一个选择对话框。如果选择在真机运行,ADT会直接将程序安装在手机上。


3.  安装、卸载和运行程序(adb install、adb uninstall和am)

       在Eclipse中运行Android程序必须得有Android源码工程。那如果只有apk文件(Android应用程序的发行包,相当于 Windows中的exe文件)该如何安装和运行呢?答案就是adb命令。假设我们要安装一个ebook.apk文件,可以使用如下的命令。
  adb install ebook.apk
      假设ebook.apk中的package是net.blogjava.mobile.ebook,可以使用如下的命令卸载这个应用程序。
  adb uninstall net.blogjava.mobile.ebook
      关于package的概念在以后的学习中会逐渐体会到。现在只要知道package是Android应用程序的唯一标识即可。如果在安装程序之前,该程序 已经在模拟器或真机上存在了,需要先使用上面的命令卸载这个应用程序,然后再安装。或使用下面的命令重新安装。
  adb install -r ebook.apk
      在卸载应用程序时可以加上-k命令行参数保留数据和缓冲目录,只卸载应用程序。命令如下所示。
  adb uninstall -k net.blogjava.mobile.ebook
      如果机器上有多个模拟器或真机实例,需要使用-s命令行参数指定具体的模拟器或真机。例如,下面的命令分别在模拟器和真机上安装、重新安装和卸载应用程序。
  在emulator-5554模拟器上安装ebook.apk
  adb -s emulator-5554 install ebook.apk
  在真机上安装ebook.apk
  adb -s HT9BYL904399 install ebook.apk
  在emulator-5554模拟器上重新安装ebook.apk
  adb -s emulator-5554 install -r ebook.apk
  在真机上重新安装ebook.apk
  adb -s HT9BYL904399 install -r ebook.apk
  在emulator-5554模拟器上卸载ebook.apk(不保留数据和缓冲目录)
  adb -s emulator-5554 uninstall net.blogjava.mobile.ebook
  在真机上卸载ebook.apk(保留数据和缓冲目录)
  adb -s HT9BYL904399 uninstall -k net.blogjava.mobile.ebook


如果想在模拟器或真机上运行已安装的应用程序,除了直接在模拟器或真机上操作外,还可以使用如下的命令直接运行程序。
  在emulator-5554模拟器上运行ebook.apk
  adb -s emulator-5554 shell am start -n net.blogjava.mobile.ebook/net.blogjava.mobile.ebook.Main
  在真机上运行ebook.apk
  adb -s HT9BYL904399 shell am start -n net.blogjava.mobile.ebook/net.blogjava.mobile.ebook.Main
  其中Main是ebook.apk的主Activity。相当于Windows应用程序的主窗体或Web应用程序的主页面。am是shell命令。关于shell命令将在后成的部分




adb 卸载软件:
    data/data/com. ...
    
    利用adb为android手机安装软件

本文主要是记录一下在开发中常用的android的adb命令。

安装apk到手机:

adb install c:\HA_drocap2_JOY3G.apk

image

启动所安装的程序,手机要是root权限并且进入到data\app目录下:

# am start -n cn.vsp/cn.vsp.StartActivty

image

查看相应的日志:

adb logcat -s welcome:i

image

【操作命令】

1. 查看设备

adb devices

这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示

      2.安装软件

adb install

      adb install <apk文件路径> :这个命令将指定的apk文件安装到设备上

3. 卸载软件

adb uninstall <软件名>

adb uninstall -k <软件名>

如果加 -k 参数,为卸载软件但是保留配置和缓存文件.

4. 进入设备或模拟器的shell:

adb shell

通过上面的命令,就可以进入设备或模拟器的shell环境中,在这个Linux Shell中,你可以执行各种Linux的命令,另外如果只想执行一条shell命令,可以采用以下的方式:

adb shell [command]

如:adb shell dmesg会打印出内核的调试信息。

5. 发布端口

可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:

adb forward tcp:5555 tcp:8000

6. 从电脑上发送文件到设备

adb push <本地路径> <远程路径>

用push命令可以把本机电脑上的文件或者文件夹复制到设备(手机)

7. 从设备上下载文件到电脑

adb pull <远程路径> <本地路径>

用pull命令可以把设备(手机)上的文件或者文件夹复制到本机电脑

8、查看bug报告

adb bugreport

9、记录无线通讯日志

一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录:

adb shell

logcat -b radio

10、获取设备的ID和序列号

adb get-product

adb get-serialno

repo


#!/bin/sh

## repo default configuration
##
REPO_URL='https://code.google.com/p/git-repo/'
REPO_REV='stable'

# Copyright (C) 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

magic='--calling-python-from-/bin/sh--'
"""exec" python -E "$0" "$@" """#$magic"
if __name__ == '__main__':
  import sys
  if sys.argv[-1] == '#%s' % magic:
    del sys.argv[-1]
del magic

# increment this whenever we make important changes to this script
VERSION = (1, 15)

# increment this if the MAINTAINER_KEYS block is modified
KEYRING_VERSION = (1,0)
MAINTAINER_KEYS = """

     Repo Maintainer <repo@android.kernel.org>
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

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
=CMiZ
-----END PGP PUBLIC KEY BLOCK-----
"""

GIT = 'git'                     # our git command
MIN_GIT_VERSION = (1, 5, 4)     # minimum supported git version
repodir = '.repo'               # name of repo's private directory
S_repo = 'repo'                 # special repo reposiory
S_manifests = 'manifests'       # special manifest repository
REPO_MAIN = S_repo + '/main.py' # main script


import optparse
import os
import re
import readline
import subprocess
import sys
import urllib2

home_dot_repo = os.path.expanduser('~/.repoconfig')
gpg_dir = os.path.join(home_dot_repo, 'gnupg')

extra_args = []
init_optparse = optparse.OptionParser(usage="repo init -u url [options]")

# Logging
group = init_optparse.add_option_group('Logging options')
group.add_option('-q', '--quiet',
                 dest="quiet", action="store_true", default=False,
                 help="be quiet")

# Manifest
group = init_optparse.add_option_group('Manifest options')
group.add_option('-u', '--manifest-url',
                 dest='manifest_url',
                 help='manifest repository location', metavar='URL')
group.add_option('-b', '--manifest-branch',
                 dest='manifest_branch',
                 help='manifest branch or revision', metavar='REVISION')
group.add_option('-m', '--manifest-name',
                 dest='manifest_name',
                 help='initial manifest file', metavar='NAME.xml')
group.add_option('--mirror',
                 dest='mirror', action='store_true',
                 help='mirror the forrest')
group.add_option('--reference',
                 dest='reference',
                 help='location of mirror directory', metavar='DIR')
group.add_option('--depth', type='int', default=None,
                 dest='depth',
                 help='create a shallow clone with given depth; see git clone')
group.add_option('-g', '--groups',
                 dest='groups', default="",
                 help='restrict manifest projects to ones with a specified group',
                 metavar='GROUP')


# Tool
group = init_optparse.add_option_group('repo Version options')
group.add_option('--repo-url',
                 dest='repo_url',
                 help='repo repository location', metavar='URL')
group.add_option('--repo-branch',
                 dest='repo_branch',
                 help='repo branch or revision', metavar='REVISION')
group.add_option('--no-repo-verify',
                 dest='no_repo_verify', action='store_true',
                 help='do not verify repo source code')

# Other
group = init_optparse.add_option_group('Other options')
group.add_option('--config-name',
                 dest='config_name', action="store_true", default=False,
                 help='Always prompt for name/e-mail')

class CloneFailure(Exception):
  """Indicate the remote clone of repo itself failed.
  """


def _Init(args):
  """Installs repo by cloning it over the network.
  """
  opt, args = init_optparse.parse_args(args)
  if args:
    init_optparse.print_usage()
    sys.exit(1)

  url = opt.repo_url
  if not url:
    url = REPO_URL
    extra_args.append('--repo-url=%s' % url)

  branch = opt.repo_branch
  if not branch:
    branch = REPO_REV
    extra_args.append('--repo-branch=%s' % branch)

  if branch.startswith('refs/heads/'):
    branch = branch[len('refs/heads/'):]
  if branch.startswith('refs/'):
    print >>sys.stderr, "fatal: invalid branch name '%s'" % branch
    raise CloneFailure()

  if not os.path.isdir(repodir):
    try:
      os.mkdir(repodir)
    except OSError, e:
      print >>sys.stderr, \
            'fatal: cannot make %s directory: %s' % (
            repodir, e.strerror)
      # Don't faise CloneFailure; that would delete the
      # name. Instead exit immediately.
      #
      sys.exit(1)

  _CheckGitVersion()
  try:
    if _NeedSetupGnuPG():
      can_verify = _SetupGnuPG(opt.quiet)
    else:
      can_verify = True

    dst = os.path.abspath(os.path.join(repodir, S_repo))
    _Clone(url, dst, opt.quiet)

    if can_verify and not opt.no_repo_verify:
      rev = _Verify(dst, branch, opt.quiet)
    else:
      rev = 'refs/remotes/origin/%s^0' % branch

    _Checkout(dst, branch, rev, opt.quiet)
  except CloneFailure:
    if opt.quiet:
      print >>sys.stderr, \
        'fatal: repo init failed; run without --quiet to see why'
    raise


def _CheckGitVersion():
  cmd = [GIT, '--version']
  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
  ver_str = proc.stdout.read().strip()
  proc.stdout.close()
  proc.wait()

  if not ver_str.startswith('git version '):
    print >>sys.stderr, 'error: "%s" unsupported' % ver_str
    raise CloneFailure()

  ver_str = ver_str[len('git version '):].strip()
  ver_act = tuple(map(lambda x: int(x), ver_str.split('.')[0:3]))
  if ver_act < MIN_GIT_VERSION:
    need = '.'.join(map(lambda x: str(x), MIN_GIT_VERSION))
    print >>sys.stderr, 'fatal: git %s or later required' % need
    raise CloneFailure()


def _NeedSetupGnuPG():
  if not os.path.isdir(home_dot_repo):
    return True

  kv = os.path.join(home_dot_repo, 'keyring-version')
  if not os.path.exists(kv):
    return True

  kv = open(kv).read()
  if not kv:
    return True

  kv = tuple(map(lambda x: int(x), kv.split('.')))
  if kv < KEYRING_VERSION:
    return True
  return False


def _SetupGnuPG(quiet):
  if not os.path.isdir(home_dot_repo):
    try:
      os.mkdir(home_dot_repo)
    except OSError, e:
      print >>sys.stderr, \
            'fatal: cannot make %s directory: %s' % (
            home_dot_repo, e.strerror)
      sys.exit(1)

  if not os.path.isdir(gpg_dir):
    try:
      os.mkdir(gpg_dir, 0700)
    except OSError, e:
      print >>sys.stderr, \
            'fatal: cannot make %s directory: %s' % (
            gpg_dir, e.strerror)
      sys.exit(1)

  env = os.environ.copy()
  env['GNUPGHOME'] = gpg_dir.encode()

  cmd = ['gpg', '--import']
  try:
    proc = subprocess.Popen(cmd,
                            env = env,
                            stdin = subprocess.PIPE)
  except OSError, e:
    if not quiet:
      print >>sys.stderr, 'warning: gpg (GnuPG) is not available.'
      print >>sys.stderr, 'warning: Installing it is strongly encouraged.'
      print >>sys.stderr
    return False

  proc.stdin.write(MAINTAINER_KEYS)
  proc.stdin.close()

  if proc.wait() != 0:
    print >>sys.stderr, 'fatal: registering repo maintainer keys failed'
    sys.exit(1)
  print

  fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
  fd.write('.'.join(map(lambda x: str(x), KEYRING_VERSION)) + '\n')
  fd.close()
  return True


def _SetConfig(local, name, value):
  """Set a git configuration option to the specified value.
  """
  cmd = [GIT, 'config', name, value]
  if subprocess.Popen(cmd, cwd = local).wait() != 0:
    raise CloneFailure()


def _InitHttp():
  handlers = []

  mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
  try:
    import netrc
    n = netrc.netrc()
    for host in n.hosts:
      p = n.hosts[host]
      mgr.add_password(p[1], 'http://%s/'  % host, p[0], p[2])
      mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
  except:
    pass
  handlers.append(urllib2.HTTPBasicAuthHandler(mgr))
  handlers.append(urllib2.HTTPDigestAuthHandler(mgr))

  if 'http_proxy' in os.environ:
    url = os.environ['http_proxy']
    handlers.append(urllib2.ProxyHandler({'http': url, 'https': url}))
  if 'REPO_CURL_VERBOSE' in os.environ:
    handlers.append(urllib2.HTTPHandler(debuglevel=1))
    handlers.append(urllib2.HTTPSHandler(debuglevel=1))
  urllib2.install_opener(urllib2.build_opener(*handlers))

def _Fetch(url, local, src, quiet):
  if not quiet:
    print >>sys.stderr, 'Get %s' % url

  cmd = [GIT, 'fetch']
  if quiet:
    cmd.append('--quiet')
    err = subprocess.PIPE
  else:
    err = None
  cmd.append(src)
  cmd.append('+refs/heads/*:refs/remotes/origin/*')
  cmd.append('refs/tags/*:refs/tags/*')

  proc = subprocess.Popen(cmd, cwd = local, stderr = err)
  if err:
    proc.stderr.read()
    proc.stderr.close()
  if proc.wait() != 0:
    raise CloneFailure()

def _DownloadBundle(url, local, quiet):
  if not url.endswith('/'):
    url += '/'
  url += 'clone.bundle'

  proc = subprocess.Popen(
    [GIT, 'config', '--get-regexp', 'url.*.insteadof'],
    cwd = local,
    stdout = subprocess.PIPE)
  for line in proc.stdout:
    m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
    if m:
      new_url = m.group(1)
      old_url = m.group(2)
      if url.startswith(old_url):
        url = new_url + url[len(old_url):]
        break
  proc.stdout.close()
  proc.wait()

  if not url.startswith('http:') and not url.startswith('https:'):
    return False

  dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
  try:
    try:
      r = urllib2.urlopen(url)
    except urllib2.HTTPError, e:
      if e.code == 404:
        return False
      print >>sys.stderr, 'fatal: Cannot get %s' % url
      print >>sys.stderr, 'fatal: HTTP error %s' % e.code
      raise CloneFailure()
    except urllib2.URLError, e:
      print >>sys.stderr, 'fatal: Cannot get %s' % url
      print >>sys.stderr, 'fatal: error %s' % e.reason
      raise CloneFailure()
    try:
      if not quiet:
        print >>sys.stderr, 'Get %s' % url
      while True:
        buf = r.read(8192)
        if buf == '':
          return True
        dest.write(buf)
    finally:
      r.close()
  finally:
    dest.close()

def _ImportBundle(local):
  path = os.path.join(local, '.git', 'clone.bundle')
  try:
    _Fetch(local, local, path, True)
  finally:
    os.remove(path)

def _Clone(url, local, quiet):
  """Clones a git repository to a new subdirectory of repodir
  """
  try:
    os.mkdir(local)
  except OSError, e:
    print >>sys.stderr, \
          'fatal: cannot make %s directory: %s' \
          % (local, e.strerror)
    raise CloneFailure()

  cmd = [GIT, 'init', '--quiet']
  try:
    proc = subprocess.Popen(cmd, cwd = local)
  except OSError, e:
    print >>sys.stderr
    print >>sys.stderr, "fatal: '%s' is not available" % GIT
    print >>sys.stderr, 'fatal: %s' % e
    print >>sys.stderr
    print >>sys.stderr, 'Please make sure %s is installed'\
                        ' and in your path.' % GIT
    raise CloneFailure()
  if proc.wait() != 0:
    print >>sys.stderr, 'fatal: could not create %s' % local
    raise CloneFailure()

  _InitHttp()
  _SetConfig(local, 'remote.origin.url', url)
  _SetConfig(local, 'remote.origin.fetch',
                    '+refs/heads/*:refs/remotes/origin/*')
  if _DownloadBundle(url, local, quiet):
    _ImportBundle(local)
  else:
    _Fetch(url, local, 'origin', quiet)


def _Verify(cwd, branch, quiet):
  """Verify the branch has been signed by a tag.
  """
  cmd = [GIT, 'describe', 'origin/%s' % branch]
  proc = subprocess.Popen(cmd,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          cwd = cwd)
  cur = proc.stdout.read().strip()
  proc.stdout.close()

  proc.stderr.read()
  proc.stderr.close()

  if proc.wait() != 0 or not cur:
    print >>sys.stderr
    print >>sys.stderr,\
      "fatal: branch '%s' has not been signed" \
      % branch
    raise CloneFailure()

  m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
  if m:
    cur = m.group(1)
    if not quiet:
      print >>sys.stderr
      print >>sys.stderr, \
        "info: Ignoring branch '%s'; using tagged release '%s'" \
        % (branch, cur)
      print >>sys.stderr

  env = os.environ.copy()
  env['GNUPGHOME'] = gpg_dir.encode()

  cmd = [GIT, 'tag', '-v', cur]
  proc = subprocess.Popen(cmd,
                          stdout = subprocess.PIPE,
                          stderr = subprocess.PIPE,
                          cwd = cwd,
                          env = env)
  out = proc.stdout.read()
  proc.stdout.close()

  err = proc.stderr.read()
  proc.stderr.close()

  if proc.wait() != 0:
    print >>sys.stderr
    print >>sys.stderr, out
    print >>sys.stderr, err
    print >>sys.stderr
    raise CloneFailure()
  return '%s^0' % cur


def _Checkout(cwd, branch, rev, quiet):
  """Checkout an upstream branch into the repository and track it.
  """
  cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
  if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
    raise CloneFailure()

  _SetConfig(cwd, 'branch.default.remote', 'origin')
  _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)

  cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
  if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
    raise CloneFailure()

  cmd = [GIT, 'read-tree', '--reset', '-u']
  if not quiet:
    cmd.append('-v')
  cmd.append('HEAD')
  if subprocess.Popen(cmd, cwd = cwd).wait() != 0:
    raise CloneFailure()


def _FindRepo():
  """Look for a repo installation, starting at the current directory.
  """
  dir = os.getcwd()
  repo = None

  olddir = None
  while dir != '/' \
    and dir != olddir \
    and not repo:
    repo = os.path.join(dir, repodir, REPO_MAIN)
    if not os.path.isfile(repo):
      repo = None
      olddir = dir
      dir = os.path.dirname(dir)
  return (repo, os.path.join(dir, repodir))


class _Options:
  help = False


def _ParseArguments(args):
  cmd = None
  opt = _Options()
  arg = []

  for i in xrange(0, len(args)):
    a = args[i]
    if a == '-h' or a == '--help':
      opt.help = True

    elif not a.startswith('-'):
      cmd = a
      arg = args[i + 1:]
      break
  return cmd, opt, arg


def _Usage():
  print >>sys.stderr,\
"""usage: repo COMMAND [ARGS]

repo is not yet installed.  Use "repo init" to install it here.

The most commonly used repo commands are:

  init      Install repo in the current working directory
  help      Display detailed help on a command

For access to the full online help, install repo ("repo init").
"""
  sys.exit(1)


def _Help(args):
  if args:
    if args[0] == 'init':
      init_optparse.print_help()
      sys.exit(0)
    else:
      print >>sys.stderr,\
      "error: '%s' is not a bootstrap command.\n"\
      '        For access to online help, install repo ("repo init").'\
      % args[0]
  else:
    _Usage()
  sys.exit(1)


def _NotInstalled():
  print >>sys.stderr,\
'error: repo is not installed.  Use "repo init" to install it here.'
  sys.exit(1)


def _NoCommands(cmd):
  print >>sys.stderr,\
"""error: command '%s' requires repo to be installed first.
       Use "repo init" to install it here.""" % cmd
  sys.exit(1)


def _RunSelf(wrapper_path):
  my_dir = os.path.dirname(wrapper_path)
  my_main = os.path.join(my_dir, 'main.py')
  my_git = os.path.join(my_dir, '.git')

  if os.path.isfile(my_main) and os.path.isdir(my_git):
    for name in ['git_config.py',
                 'project.py',
                 'subcmds']:
      if not os.path.exists(os.path.join(my_dir, name)):
        return None, None
    return my_main, my_git
  return None, None


def _SetDefaultsTo(gitdir):
  global REPO_URL
  global REPO_REV

  REPO_URL = gitdir
  proc = subprocess.Popen([GIT,
                           '--git-dir=%s' % gitdir,
                           'symbolic-ref',
                           'HEAD'],
                          stdout = subprocess.PIPE,
                          stderr = subprocess.PIPE)
  REPO_REV = proc.stdout.read().strip()
  proc.stdout.close()

  proc.stderr.read()
  proc.stderr.close()

  if proc.wait() != 0:
    print >>sys.stderr, 'fatal: %s has no current branch' % gitdir
    sys.exit(1)


def main(orig_args):
  main, dir = _FindRepo()
  cmd, opt, args = _ParseArguments(orig_args)

  wrapper_path = os.path.abspath(__file__)
  my_main, my_git = _RunSelf(wrapper_path)

  if not main:
    if opt.help:
      _Usage()
    if cmd == 'help':
      _Help(args)
    if not cmd:
      _NotInstalled()
    if cmd == 'init':
      if my_git:
        _SetDefaultsTo(my_git)
      try:
        _Init(args)
      except CloneFailure:
        for root, dirs, files in os.walk(repodir, topdown=False):
          for name in files:
            os.remove(os.path.join(root, name))
          for name in dirs:
            os.rmdir(os.path.join(root, name))
        os.rmdir(repodir)
        sys.exit(1)
      main, dir = _FindRepo()
    else:
      _NoCommands(cmd)

  if my_main:
    main = my_main

  ver_str = '.'.join(map(lambda x: str(x), VERSION))
  me = [main,
        '--repo-dir=%s' % dir,
        '--wrapper-version=%s' % ver_str,
        '--wrapper-path=%s' % wrapper_path,
        '--']
  me.extend(orig_args)
  me.extend(extra_args)
  try:
    os.execv(main, me)
  except OSError, e:
    print >>sys.stderr, "fatal: unable to start %s" % main
    print >>sys.stderr, "fatal: %s" % e
    sys.exit(148)


if __name__ == '__main__':
  main(sys.argv[1:])


标准版pad同步代码编译方法

北京
repo init --repo-url bearr:android/tools/repo -u bearr:android/platform/manifest -b ics-wow -m crane-wow.xml

repo sync

. build/envsetup.h

lunch

选择crane-wowpad

make -j4

使用深圳服务器同步代码方法

repo init --repo-url venusr:allwinner/tools/repo -u venusr:allwinner/platform/manifest -b ics-wow -m crane-wow.xml

repo sync

. build/envsetup.h

lunch

选择crane-wowpad

make -j4





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值