forked from vacancy/Jacinle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
41 lines (32 loc) · 985 Bytes
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# File : cli.py
# Author : Jiayuan Mao
# Email : [email protected]
# Date : 04/23/2018
#
# This file is part of Jacinle.
# Distributed under terms of the MIT license.
import os
import os.path as osp
import sys
import jacinle.io as io
from jacinle.cli.git import get_git_revision_hash
def escape_desc_name(filename):
basename = osp.basename(filename)
if basename.endswith('.py'):
basename = basename[:-3]
name = basename.replace('.', '_')
return name
def ensure_path(path):
if not osp.exists(path):
print('Creating directory: "{}".'.format(path))
os.makedirs(path, exist_ok=True)
return path
def dump_metainfo(metainfo=None, **kwargs):
if metainfo is None:
metainfo = {}
metainfo.update(kwargs)
metainfo.setdefault('_cmd', ' '.join(sys.argv))
metainfo.setdefault('_git', get_git_revision_hash())
return io.dumps_json(metainfo, compressed=False)