Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def command_db_clone(url, dbname):
"""
Clone an existing database from a Git repo
Shortcut for `git clone GIT_URL $HOME/.linkpad/$DBNAME`
"""
if db_exists(dbname):
sys.exit("Error: database '{}' already exists".format(dbname))
if not os.path.isdir(LINKPAD_BASEDIR):
sh.mkdir('-p', LINKPAD_BASEDIR)
sh.cd(LINKPAD_BASEDIR)
sh.git('clone', url, dbname, _fg=True)
click.echo()
dbpath = os.path.join(LINKPAD_BASEDIR, dbname)
if not db_exists(dbname):
click.echo("Deleting '{}' ...".format(dbpath))
sh.rm('-rf', dbpath)
sys.exit("Error: url '{}' did not contain a valid Linkpad database".format(url))
click.echo("cloned '{}'".format(dbpath))
csv = '{}.csv'.format(base)
txt = '{}.txt'.format(base)
if os.path.exists(csv):
converted_boms.append(csv)
if os.path.exists(txt):
converted_boms.append(txt)
boms += converted_boms
# Get the output file name
output_name = fab_zip.split('_to_fab')[0] + '_{}.zip'.format(args.date)
# Actually make the zip
# Generate the folders we use to organize things
mkdir(FAB_FOLDER)
mkdir(ASSEM_FOLDER)
mkdir(IMAGE_FOLDER)
# Put the contents of the zip files in the folders
# This way we don't have to replicate that logic
unzip(fab_zip, '-d', FAB_FOLDER)
unzip(assem_zip, '-d', ASSEM_FOLDER)
# Put the images in the images folder
for jpg in jpgs:
cp(jpg, IMAGE_FOLDER)
# Get the filenames for fab
fab_files = glob.glob('{}/*'.format(FAB_FOLDER))
assem_files = glob.glob('{}/*'.format(ASSEM_FOLDER))
image_files = glob.glob('{}/*'.format(IMAGE_FOLDER))
def pull(self, src_path, file_name, dst_path='.'):
if not os.path.exists(dst_path):
sh.mkdir("-p", dst_path)
src_file = "%s/%s" % (src_path, file_name)
dst_file = "%s/%s" % (dst_path, file_name)
if os.path.exists(dst_file):
sh.rm('-f', dst_file)
six.print_("Pull %s to %s" % (src_file, dst_path))
if self.system == SystemType.android:
sh_commands.adb_pull(
src_file, dst_file, self.address)
elif self.system == SystemType.arm_linux:
try:
sh.scp('-r', '%s@%s:%s' % (self.username,
self.address,
src_file),
dst_file)
except sh.ErrorReturnCode_1 as e:
six.print_("Pull Failed !", file=sys.stderr)
arch = self.ctx.archs[0]
if len(self.ctx.archs) > 1:
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
info('Bootstrap running with arch {}'.format(arch))
with current_directory(self.dist_dir):
info('Copying python distribution')
if not exists('private') and not self.ctx.python_recipe.from_crystax:
shprint(sh.mkdir, 'private')
if not exists('crystax_python') and self.ctx.python_recipe.from_crystax:
shprint(sh.mkdir, 'crystax_python')
shprint(sh.mkdir, 'crystax_python/crystax_python')
if not exists('assets'):
shprint(sh.mkdir, 'assets')
hostpython = sh.Command(self.ctx.hostpython)
if not self.ctx.python_recipe.from_crystax:
try:
shprint(hostpython, '-OO', '-m', 'compileall',
self.ctx.get_python_install_dir(),
_tail=10, _filterout="^Listing")
except sh.ErrorReturnCode:
pass
if not exists('python-install'):
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
self.distribute_aars(arch)
self.distribute_javaclasses(self.ctx.javaclass_dir)
def build_arch(self, arch):
with current_directory(self.get_build_dir(arch.arch)):
env = self.get_recipe_env(arch)
configure = sh.Command('./configure')
shprint(configure,
'--host=arm-linux',
_env=env)
shprint(sh.make, '-j4', _env=env)
shprint(sh.mkdir, 'include')
shprint(sh.cp, '-a', 'gmp.h', 'include/gmp.h')
shprint(sh.cp, '-a', '.libs/libgmp.so', join(self.ctx.get_libs_dir(arch.arch), 'libgmp.so'))
shprint(sh.cp, '-a', '.libs/libgmp.so', join(self.ctx.get_libs_dir(''), 'libgmp.so')) # also copy to libs_collections/
def gen_encrypted_opencl_source(codegen_path="mace/codegen"):
sh.mkdir("-p", "%s/opencl" % codegen_path)
encrypt_opencl_codegen("./mace/ops/opencl/cl/",
"mace/codegen/opencl/opencl_encrypt_program.cc")
def prebuild_arch(self, arch):
super(Sqlite3Recipe, self).prebuild_arch(arch)
# Copy the Android make file
sh.mkdir('-p', join(self.get_build_dir(arch.arch), 'jni'))
shutil.copyfile(join(self.get_recipe_dir(), 'Android.mk'),
join(self.get_build_dir(arch.arch), 'jni/Android.mk'))
def download(url, filename):
filedir = os.path.dirname(filename)
sh.mkdir('-p', filedir)
print '%s --> %s' % (url, filename)
resp = requests.get(url)
if resp.ok:
f = open(filename, 'w')
f.write(resp.content)
f.close()
else:
print 'Error: %s' % resp.status_code
return resp.ok
def _create_mount_dir(self, mount_dir):
LOG.info('Creating Directory %(mount_dir)s...',
{'mount_dir': mount_dir})
sh.mkdir('-p', mount_dir)
LOG.info('Directory: %(mount_dir)s successfully created!',
{'mount_dir': mount_dir})
def prepare_build_dir(self):
'''Ensure that a build dir exists for the recipe. This same single
dir will be used for building all different archs.'''
self.build_dir = self.get_build_dir()
shprint(sh.cp, '-r',
join(self.bootstrap_dir, 'build'),
self.build_dir)
if self.ctx.symlink_java_src:
info('Symlinking java src instead of copying')
shprint(sh.rm, '-r', join(self.build_dir, 'src'))
shprint(sh.mkdir, join(self.build_dir, 'src'))
for dirn in listdir(join(self.bootstrap_dir, 'build', 'src')):
shprint(sh.ln, '-s', join(self.bootstrap_dir, 'build', 'src', dirn),
join(self.build_dir, 'src'))
with current_directory(self.build_dir):
with open('project.properties', 'w') as fileh:
fileh.write('target=android-{}'.format(self.ctx.android_api))