Пример #1
0
    def test_svn_revsets(self):
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        defaults = {'date': None, 'rev': ['fromsvn()'], 'user': None}

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 1:3 ')

        defaults = {'date': None, 'rev': ['svnrev(2)'], 'user': None}

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 ')

        defaults = {'date': None, 'rev': ['fromsvn(1)'], 'user': None}

        self.assertRaises(error.ParseError,
                          commands.log,
                          self.ui(),
                          repo,
                          template='{rev}:{svnrev} ',
                          **defaults)

        defaults = {'date': None, 'rev': ['svnrev(1, 2)'], 'user': None}

        self.assertRaises(error.ParseError,
                          commands.log,
                          self.ui(),
                          repo,
                          template='{rev}:{svnrev} ',
                          **defaults)
Пример #2
0
def get_version_info(data_dir, path, info_encoding):
    """
    Obtains information about a file via Mercurial Python API

    arguments:
    data_dir -- path to a Mercurial repository (= riki data directory)
    path -- a file we want log information about
    info_encoding -- encoding used on data fetched from hg (system dependent)

    returns:
    a dictionary {'date': str, 'user': str, 'changeset': str, 'summary' : str}
    """
    from mercurial import commands, ui, hg, error

    if type(path) is unicode:  # mercurial API does not like unicode path
        path = path.encode('utf-8')
    ans = {}
    try:
        repo = hg.repository(ui.ui(), data_dir)
        repo.ui.pushbuffer()
        commands.log(repo.ui, repo, path)
        output = repo.ui.popbuffer()
        for item in re.split(r'\n', output):
            srch = re.match(r'^(\w+):\s+(.+)$', item)
            if srch:
                v = srch.groups()[1]
                ans[srch.groups()[0]] = v if info_encoding.lower() == 'utf-8' else v.decode(info_encoding)
    except error.Abort as e:
        logging.getLogger(__name__).warning('Failed to fetch version info about [%s]: %s' % (path, e))
    if 'user' not in ans:
        ans['user'] = '******'
    return ans
Пример #3
0
def urls(ui, repo, *paths, **opts):
    '''Display a list of urls for the last several commits.
    These are merely heuristic guesses and are intended for pasting into
    bugs after landing. If that makes no sense to you, then you are probably
    not the intended audience. It's mainly a Mozilla thing.

    Note that this will display the URL for your default repo, which may very
    well be something local. So you may need to give your outbound repo as
    an argument.
'''

    opts['template'] = '{node|short} {desc|firstline}\n'
    ui.pushbuffer()
    commands.log(ui, repo, **opts)
    lines = ui.popbuffer()
    if len(paths) == 0:
        paths = ['default']
    ui.pushbuffer()
    commands.paths(ui, repo, *paths)
    url = ui.popbuffer().rstrip()
    url = re.sub(r'^\w+', 'http', url)
    url = re.sub(r'(\w|\%|\.|-)+\@', '', url) # Remove usernames
    for line in lines.split('\n'):
        if len(line) > 0:
            rev, desc = line.split(' ', 1)
            ui.write(url + '/rev/' + rev + '\n  ' + desc + '\n\n')
Пример #4
0
    def test_svn_keywords(self):
        defaults = {'date': None, 'rev': None, 'user': None, 'graph': True}
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        ui = CapturingUI()
        commands.log(ui,
                     repo,
                     template=('  rev: {rev} svnrev:{svnrev} '
                               'svnpath:{svnpath} svnuuid:{svnuuid}\n'),
                     **defaults)
        print ui._output
        self.assertEqual(
            ui._output.strip(), '''
  rev: 2 svnrev: svnpath: svnuuid:
@
|
  rev: 1 svnrev:3 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
o
|
  rev: 0 svnrev:2 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
o
'''.strip())
Пример #5
0
    def _getLog(self, limit=None):
        """Read log entries into a list of dictionaries."""
        self.ui.pushbuffer()
        commands.log(self.ui,
                     self.repo,
                     limit=limit,
                     date=None,
                     rev=None,
                     user=None)
        res = self.ui.popbuffer().strip()

        logList = []
        for logentry in res.split("\n\n"):
            log = {}
            logList.append(log)
            for line in logentry.split("\n"):
                k, v = line.split(":", 1)
                assert k in ("changeset", "tag", "user", "date", "summary")
                log[k.strip()] = v.strip()
            log["parsed_date"] = util.parseTimeString(log["date"])
            local_id, unid = log["changeset"].split(":")
            log["local_id"] = int(local_id)
            log["unid"] = unid
#        pprint(logList)
        return logList
Пример #6
0
    def test_svn_revsets(self):
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        defaults = {'date': None, 'rev': ['fromsvn()'], 'user': None}

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 1:3 ')

        defaults = {'date': None, 'rev': ['svnrev(2)'], 'user': None}

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 ')

        defaults = {'date': None, 'rev': ['fromsvn(1)'], 'user': None}

        self.assertRaises(error.ParseError,
                          commands.log, self.ui(), repo,
                          template='{rev}:{svnrev} ', **defaults)

        defaults = {'date': None, 'rev': ['svnrev(1, 2)'], 'user': None}

        self.assertRaises(error.ParseError,
                          commands.log, self.ui(), repo,
                          template='{rev}:{svnrev} ', **defaults)
Пример #7
0
def urls(ui, repo, *paths, **opts):
    '''Display a list of urls for the last several commits.
    These are merely heuristic guesses and are intended for pasting into
    bugs after landing. If that makes no sense to you, then you are probably
    not the intended audience. It's mainly a Mozilla thing.

    Note that this will display the URL for your default repo, which may very
    well be something local. So you may need to give your outbound repo as
    an argument.
'''

    opts['template'] = '{node|short} {desc|firstline}\n'
    ui.pushbuffer()
    commands.log(ui, repo, **opts)
    lines = ui.popbuffer()
    if len(paths) == 0:
        paths = ['default']
    ui.pushbuffer()
    commands.paths(ui, repo, *paths)
    url = ui.popbuffer().rstrip()
    url = re.sub(r'^\w+', 'http', url)
    url = re.sub(r'(\w|\%|\.|-)+\@', '', url) # Remove usernames
    for line in lines.split('\n'):
        if len(line) > 0:
            rev, desc = line.split(' ', 1)
            ui.write(url + '/rev/' + rev + '\n  ' + desc + '\n\n')
Пример #8
0
def get_version_info(repo_path: str, path: str,
                     info_encoding: str) -> RevisionInfo:
    """
    Obtains information about a file via Mercurial Python API

    arguments:
    path -- a file we want revision information about
    info_encoding -- encoding used on data fetched from hg (system dependent)

    returns:
    a dictionary {'date': str, 'user': str, 'changeset': str, 'summary' : str}
    """
    from mercurial import ui, hg, commands

    ans = {}
    try:
        u = ui.ui()
        repo = hg.repository(u, repo_path.encode())
        u.pushbuffer()
        commands.log(u, repo, path.encode(), limit=1)
        output = u.popbuffer()
        for item in re.split(r'\n', output.decode()):
            srch = re.match(r'^(\w+):\s+(.+)$', item)
            if srch:
                v = srch.groups()[1]
                ans[srch.groups()[0]] = v if info_encoding.lower(
                ) == 'utf-8' else v.decode(info_encoding)
    except Exception as e:
        logging.getLogger(__name__).warning(
            'Failed to fetch version info about [%s]: %s' % (path, e))
    rev_info = RevisionInfo(**ans)
    return rev_info
Пример #9
0
 def list_commits(self, branch):
     if self.vcs_type == 'git':
         branch = branch or 'HEAD'
         # using walker and a ref (branch)
         branches = self.r.get_refs()
         if branch not in branches:
             branch = 'HEAD'
         if branch in branches:
             w = self.r.get_walker([self.r.refs[branch]])
             #w = r.get_walker([r.refs['refs/heads/sqlite']])
             l = [x.commit for x in w]
         else:
             l = ["Nothing has yet been done on your repo..."]
     elif self.vcs_type == 'hg':
         branch = branch or 'default'
         branches = self.r.branchmap().keys()
         if branch not in branches:
             branch = 'default'
         #if s['branch'] not in branches:
         try:
             self.ui.pushbuffer()
             hg.log(self.ui, self.r, branch=[branch])
             l = self.ui.popbuffer().split('\n\n')
         except:
             branch = 'default'
             l = ["Nothing has yet been done on your repo..."]
     return branch, l
Пример #10
0
def hg_log():
    opts = { 'template': '{rev} {desc}\n', 'rev': None, 'date': None, 'user': None }
    
    _ui.pushbuffer()
    commands.log(_ui, get_sandbox_repo(), **opts)
    output = _ui.popbuffer()
    
    return output
Пример #11
0
    def get_revision_before_date(self, date):
        datestr = "<%s" % self.date_as_string(date)
        branch = self.repo[None].branch()
        self.ui.pushbuffer()
        commands.log(self.ui, self.repo, branch=[branch], template="{node}\n", date=datestr, rev='', user='', limit=10)
        hexids = self.ui.popbuffer()

        #loop over up to 10 changesets to find first non-bogus one
        for hexid in hexids.split():
            if not self.changeset_is_bogus(self.repo[hexid]):
                return hexid.strip()
        return None
Пример #12
0
def security_check(ui, repo, **kwargs):
    ui.debug('running security_check\n')
    error = False

    ui.pushbuffer()
    _quiet(
        ui, lambda: commands.log(ui,
                                 repo,
                                 rev=['%s:tip' % kwargs['node']],
                                 template='{node}\n',
                                 date=None,
                                 user=None,
                                 logfile=None))
    nodes = ui.popbuffer().split('\n')

    # reenable this code if we need to blacklist a node
    for node in nodes:
        if node.startswith('8555e8551203') or node.startswith('e09bb3ece6c7'):
            ui.warn('blacklisted changeid found: node %s is blacklisted\n' %
                    node)
            error = True  # fail the push

    # Look for blacklisted bugs
    blacklist = [
        # Serrano
        580489,
        604354,
        # Wasabi
        507624,
        # Cyril
        570049,
        628834,
    ]

    bugs = re.compile('(%s)' % '|'.join([str(bug) for bug in blacklist]))

    ui.pushbuffer()
    _quiet(
        ui, lambda: commands.log(ui,
                                 repo,
                                 rev=['%s:tip' % kwargs['node']],
                                 template='{desc}',
                                 date=None,
                                 user=None,
                                 logfile=None))
    descs = ui.popbuffer()

    searchDescs = bugs.search(descs)
    if searchDescs:
        ui.warn('blacklisted bug found: %s\n' % searchDescs.groups()[0])
        error = True

    return error
Пример #13
0
    def log(self, filename):
        self.hgui.pushbuffer()
        commands.log(self.hgui, self.repo, filename, follow=True, date="", rev="", user="")
        _log=self.hgui.popbuffer()

        changesets=[_c for _c in _log.split('\n\n') if _c not in ('')]
        history=[]
        for changeset in changesets:
            _dict={}
            for _f in changeset.split("\n"):
                kkk, vvv=_f.split(": ")
                _dict[kkk.strip()]=vvv.strip()
            history.append(_dict)
        return history
Пример #14
0
def security_check(ui, repo, **kwargs):
    ui.debug("running security_check\n")
    error = False

    ui.pushbuffer()
    _quiet(
        ui,
        lambda: commands.log(
            ui, repo, rev=["%s:tip" % kwargs["node"]], template="{node}\n", date=None, user=None, logfile=None
        ),
    )
    nodes = ui.popbuffer().split("\n")

    # reenable this code if we need to blacklist a node
    for node in nodes:
        if node.startswith("8555e8551203") or node.startswith("e09bb3ece6c7"):
            ui.warn("blacklisted changeid found: node %s is blacklisted\n" % node)
            error = True  # fail the push

    # Look for blacklisted bugs
    blacklist = [
        # Serrano
        580489,
        604354,
        # Wasabi
        507624,
        # Cyril
        570049,
        628834,
    ]

    bugs = re.compile("(%s)" % "|".join([str(bug) for bug in blacklist]))

    ui.pushbuffer()
    _quiet(
        ui,
        lambda: commands.log(
            ui, repo, rev=["%s:tip" % kwargs["node"]], template="{desc}", date=None, user=None, logfile=None
        ),
    )
    descs = ui.popbuffer()

    searchDescs = bugs.search(descs)
    if searchDescs:
        ui.warn("blacklisted bug found: %s\n" % searchDescs.groups()[0])
        error = True

    return error
Пример #15
0
def perflog(ui, repo, **opts):
    timer, fm = gettimer(ui, opts)
    ui.pushbuffer()
    timer(lambda: commands.log(
        ui, repo, rev=[], date='', user='', copies=opts.get('rename')))
    ui.popbuffer()
    fm.end()
Пример #16
0
def perflog(ui, repo, **opts):
    timer, fm = gettimer(ui, opts)
    ui.pushbuffer()
    timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
                               copies=opts.get('rename')))
    ui.popbuffer()
    fm.end()
Пример #17
0
def perftemplating(ui, repo, **opts):
    timer, fm = gettimer(ui, opts)
    ui.pushbuffer()
    timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
                               template='{date|shortdate} [{rev}:{node|short}]'
                               ' {author|person}: {desc|firstline}\n'))
    ui.popbuffer()
    fm.end()
Пример #18
0
def perftemplating(ui, repo, **opts):
    timer, fm = gettimer(ui, opts)
    ui.pushbuffer()
    timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
                               template='{date|shortdate} [{rev}:{node|short}]'
                               ' {author|person}: {desc|firstline}\n'))
    ui.popbuffer()
    fm.end()
Пример #19
0
 def getLog(_ui, srepo, opts):
     _ui.pushbuffer()
     try:
         commands.log(_ui, srepo, **opts)
         logOutput = _ui.popbuffer()
     except error.ParseError, e:
         # Some mercurial versions have a bug that results in
         # saving a subrepo node id in the .hgsubstate file
         # which ends with a "+" character. If that is the
         # case, add a warning to the output, but try to
         # get the revision information anyway
         logOutput = ''
         for n, rev in enumerate(opts['rev']):
             if rev.endswith('+'):
                 logOutput += _('[WARNING] Invalid subrepo '
                     'revision ID:\n\t%s\n\n') % rev
                 opts['rev'][n] = rev[:-1]
         commands.log(_ui, srepo, **opts)
         logOutput += _ui.popbuffer()
Пример #20
0
 def getLog(_ui, srepo, opts):
     _ui.pushbuffer()
     try:
         commands.log(_ui, srepo, **opts)
         logOutput = _ui.popbuffer()
     except error.ParseError, e:
         # Some mercurial versions have a bug that results in
         # saving a subrepo node id in the .hgsubstate file
         # which ends with a "+" character. If that is the
         # case, add a warning to the output, but try to
         # get the revision information anyway
         logOutput = ''
         for n, rev in enumerate(opts['rev']):
             if rev.endswith('+'):
                 logOutput += _(
                     '[WARNING] Invalid subrepo '
                     'revision ID:\n\t%s\n\n') % rev
                 opts['rev'][n] = rev[:-1]
         commands.log(_ui, srepo, **opts)
         logOutput += _ui.popbuffer()
Пример #21
0
def rhlog(ui, repo, *pats, **opts):
    rev      = opts.pop('rev')
    bra0     = opts.pop('branch')
    from_rev = urllib.unquote_plus(opts.pop('from', None))
    to_rev   = urllib.unquote_plus(opts.pop('to'  , None))
    bra      = urllib.unquote_plus(opts.pop('rhbranch', None))
    from_rev = from_rev.replace('"', '\\"')
    to_rev   = to_rev.replace('"', '\\"')
    opts['rev'] = ['"%s":"%s"' % (from_rev, to_rev)]
    opts['branch'] = [bra]
    return commands.log(ui, repo, *map(urllib.unquote_plus, pats), **opts)
Пример #22
0
def glog(ui, repo, *pats, **opts):
    """show revision history alongside an ASCII revision graph

    Print a revision history alongside a revision graph drawn with
    ASCII characters.

    Nodes printed as an @ character are parents of the working
    directory.
    """
    opts['graph'] = True
    return commands.log(ui, repo, *pats, **opts)
    def _getLog(self, limit=None):
        """Read log entries into a list of dictionaries."""
        self.ui.pushbuffer()
        commands.log(self.ui, self.repo, limit=limit, date=None, rev=None, user=None)
        res = self.ui.popbuffer().strip()

        logList = []
        for logentry in res.split("\n\n"):
            log = {}
            logList.append(log)
            for line in logentry.split("\n"):
                k, v = line.split(":", 1)
                assert k in ("changeset", "tag", "user", "date", "summary")
                log[k.strip()] = v.strip()
            log["parsed_date"] = util.parseTimeString(log["date"])
            local_id, unid = log["changeset"].split(":")
            log["local_id"] = int(local_id)
            log["unid"] = unid
        #        pprint(logList)
        return logList
Пример #24
0
def rhlog(ui, repo, *pats, **opts):
    rev      = opts.pop('rev')
    bra0     = opts.pop('branch')
    from_rev = urllib.unquote_plus(opts.pop('from', None))
    to_rev   = urllib.unquote_plus(opts.pop('to'  , None))
    bra      = urllib.unquote_plus(opts.pop('rhbranch', None))
    from_rev = from_rev.replace('"', '\\"')
    to_rev   = to_rev.replace('"', '\\"')
    opts['rev'] = ['"%s":"%s"' % (from_rev, to_rev)]
    opts['branch'] = [bra]
    return commands.log(ui, repo, *map(urllib.unquote_plus, pats), **opts)
Пример #25
0
def hg_commits(filename):
    face = ui.ui()
    repo = hg.repository(face, blog_dir)
    location = get_location(filename)

    face.pushbuffer()
    commands.log(face, repo, os.path.join(blog_dir, location, filename),
            date='', rev=[], follow=True,
            template="node:{node}\ndesc:{desc}\nmove:{file_copies}\n\n")
    output = face.popbuffer()

    commit = []
    commits = []
    for line in output.splitlines():
        if line:
            commit.append(line.split(':'))
        else:
            commits.append(dict(commit))
            commit = []
    return commits
Пример #26
0
    def log(self, filename):
        self.hgui.pushbuffer()
        commands.log(self.hgui,
                     self.repo,
                     filename,
                     follow=True,
                     date="",
                     rev="",
                     user="")
        _log = self.hgui.popbuffer()

        changesets = [_c for _c in _log.split('\n\n') if _c not in ('')]
        history = []
        for changeset in changesets:
            _dict = {}
            for _f in changeset.split("\n"):
                kkk, vvv = _f.split(": ")
                _dict[kkk.strip()] = vvv.strip()
            history.append(_dict)
        return history
Пример #27
0
    def test_svn_keywords(self):
        defaults = {'date': None, 'rev': None, 'user': None, 'graph': True}
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        ui = CapturingUI()
        commands.log(ui, repo, template=('  rev: {rev} svnrev:{svnrev} '
                                         'svnpath:{svnpath} svnuuid:{svnuuid}\n'),
                     **defaults)
        print ui._output
        self.assertEqual(ui._output.strip(), '''
  rev: 2 svnrev: svnpath: svnuuid:
@
|
  rev: 1 svnrev:3 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
o
|
  rev: 0 svnrev:2 svnpath:/trunk svnuuid:df2126f7-00ab-4d49-b42c-7e981dde0bcf
o
'''.strip())
Пример #28
0
def show(ui, repo, *args, **opts):
    """show revision in detail

    This behaves similarly to :hg:`log -vp -r REV [OPTION]... [FILE]...`, or
    if called without a REV, :hg:`log -vp -r . [OPTION]...` Use
    :hg:`log` for more powerful operations than supported by hg show

    See :hg:`help templates` for more about pre-packaged styles and
    specifying custom templates.

    """
    ui.pager('show')
    if len(args) == 0:
        opts['rev'] = ['.']
        pats = []
    else:
        opts['rev'] = [args[0]]
        pats = args[1:]
        if not scmutil.revrange(repo, opts['rev']):
            h = _("if %s is a file, try `hg show . %s`") % (args[0], args[0])
            raise error.Abort(_("unknown revision %s") % args[0],
                              hint=h)

    opts['patch'] = not opts['stat']
    opts['verbose'] = True

    # Copy tracking is slow when doing a git diff. Override hgrc, and rely on
    # opts getting us a git diff if it's been requested. Ideally, we'd find and
    # fix the slowness in copy tracking, but this works for now.
    # On a commit with lots of possible copies, Bryan O'Sullivan found that this
    # reduces "time hg show" from 1.76 seconds to 0.81 seconds.
    overrides = {('diff', 'git'): opts.get('git')
                ,('diff','unified'):opts.get('unified')
                ,('ui', 'verbose'): True}
    with ui.configoverride(overrides, 'show'):
        commands.log(ui, repo, *pats, **opts)
Пример #29
0
    def getgraph(self, repo):
        """Helper function displaying a repository graph, especially
        useful when debugging comprehensive tests.
        """
        # Could be more elegant, but it works with stock hg
        _ui = testui()
        _ui.setconfig('extensions', 'graphlog', '')
        extensions.loadall(_ui)
        graphlog = extensions.find('graphlog')
        templ = """\
changeset: {rev}:{node|short} (r{svnrev})
branch:    {branches}
tags:      {tags}
summary:   {desc|firstline}
files:     {files}

"""
        _ui.pushbuffer()
        try:
            graphlog.graphlog(_ui, repo, rev=None, template=templ)
        except AttributeError:
            from mercurial import commands
            commands.log(_ui, repo, rev=None, template=templ, graph=True)
        return _ui.popbuffer()
Пример #30
0
    def test_svn_keywords(self):
        defaults = {'date': None, 'rev': None, 'user': None}
        repo = self._load_fixture_and_fetch('two_revs.svndump')

        # we want one commit that isn't from Subversion
        self.commitchanges([('foo', 'foo', 'frobnicate\n')])

        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults)
        self.assertEqual(ui._output, '0:2 1:3 2: ')
        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnpath} ', **defaults)
        self.assertEqual(ui._output, '0:/trunk 1:/trunk 2: ')
        ui = CapturingUI()
        commands.log(ui, repo, template='{rev}:{svnuuid} ', **defaults)
        self.assertEqual(ui._output,
                         ('0:df2126f7-00ab-4d49-b42c-7e981dde0bcf '
                          '1:df2126f7-00ab-4d49-b42c-7e981dde0bcf '
                          '2: '))
Пример #31
0
def qlog(ui, repo, **opts):
    """Runs the hg log command for the patch queue repo of a regular repo"""
    q = qrepo(ui, repo)
    commands.log(ui, q, **opts)
Пример #32
0
def doRun():
    """!
    Run FireSTARR projections for all matching fires based on Settings
    @return None
    """
    settings = Settings()
    sys.path.append(Settings.HOME_DIR)
    os.chdir(Settings.HOME_DIR)
    ensure_dir(settings.outbase)
    out_dir = os.path.join(settings.outbase, "output")
    ensure_dir(out_dir)
    if settings.clean:
        do_clean(settings, out_dir)
    if not settings.dont_make:
        runMake()
    try_copy(Settings.BINARY,
             os.path.join(out_dir, os.path.basename(Settings.BINARY)))
    shutil.copyfile("settings.ini", os.path.join(out_dir, "settings.ini"))
    shutil.copyfile("fuel.lut", os.path.join(out_dir, "fuel.lut"))
    from mercurial import ui, hg, commands
    u = ui.ui()
    repo = hg.repository(u, ".")
    u.pushbuffer()
    commands.log(u, repo)
    output = u.popbuffer()
    write_file(out_dir, "ver.txt", output)
    u.pushbuffer()
    commands.diff(u, repo)
    output = u.popbuffer()
    write_file(out_dir, "cur.diff", output)
    #
    os.chdir(out_dir)
    #
    cols = get_fires(settings)
    #
    fires = list(cols['FIRENAME'])
    if not (settings.fire_mask or settings.resume_mask):
        logging.info("Found {:d} fires in DFOSS".format(len(fires)))
    elif settings.fire_mask:
        fires = [fire for fire in fires if str(settings.fire_mask) in fire]
    if len(fires) > 0:
        settings.loadPerims()
    # if no settings.resume_mask then we're good to start
    found_start = not settings.resume_mask
    i = 0
    to_run = []
    scenario_args = []
    for a in list(sys.argv):
        if a in Scenario.POSSIBLE_ARGS:
            scenario_args.append(a)
    for index, row in cols.sort_values(
        ["FIRENAME"], ascending=not settings.reversed).iterrows():
        fire = row["FIRENAME"]
        found_start = found_start or settings.resume_mask in fire
        if not found_start:
            if not settings.fire_mask or fire in fires:
                i += 1
        elif fire in fires:
            logging.info("Checking fire {} {:d} of {:d}".format(
                fire, i + 1, len(fires)))
            print(row)
            # only run if we're not async or the fire mask is the current fire
            start_day = row["day"]
            start_time = row["start_time"]
            # make sure we're not calling this for the day it started
            if settings.use_perim and settings.for_date != start_day:
                day = settings.for_time.strftime("%Y-%m-%d")
                start_time = settings.for_time.strftime("%H:%M")
                if day == start_day:
                    if row["start_time"] > start_time:
                        start_time = row["start_time"]
            else:
                day = start_day
            lat = row["LATITUDE"]
            lon = row["LONGITUDE"]
            if not settings.fire_mask or str(settings.fire_mask) in fire:
                if not settings.for_date or settings.for_date >= start_day:
                    try:
                        #~ break
                        #~ print(fire, day, lat, lon, start_time, out_dir, int(row["CURRENTSIZE"]))
                        size = None if pd.isnull(row["CURRENTSIZE"]) else int(
                            row["CURRENTSIZE"])
                        if settings.override_size:
                            size = int(settings.override_size)
                        scenario = write_config(fire, day, lat, lon,
                                                start_time, out_dir, size,
                                                settings)
                        if settings.fire_mask == fire or settings.sequential:
                            t0 = timeit.default_timer()
                            run(scenario, settings.args)
                            t1 = timeit.default_timer()
                            logging.debug("Took {}s to run fire".format(t1 -
                                                                        t0))
                        else:
                            run_what = r'python.exe firestarr\firestarr.py "{}" {}'.format(
                                scenario, ' '.join(scenario_args))
                            to_run.append(run_what)
                    except Exception as e:
                        logging.fatal(e)
                        traceback.print_exc()
                        sys.exit(-1)
            i += 1
    if len(to_run) > 0:
        from multiprocessing.pool import ThreadPool
        tp = ThreadPool(Settings.POOL_SIZE)

        def run_process(run_what):
            # newlines were in weird places without this
            print(run_what + "\n", end='')
            finish_process(
                start_process(run_what, Settings.PROCESS_FLAGS,
                              Settings.HOME_DIR))

        for run_what in to_run:
            tp.apply_async(run_process, (run_what, ))
        tp.close()
        tp.join()
Пример #33
0
def perflog(ui, repo):
    ui.pushbuffer()
    timer(lambda: commands.log(ui, repo, rev=[], date='', user=''))
    ui.popbuffer()
Пример #34
0
def perflog(ui, repo):
    ui.pushbuffer()
    timer(lambda: commands.log(ui, repo, rev=[], date='', user=''))
    ui.popbuffer()