def _init(args): '''Create an empty project or reinitialize an existing one.''' path = os.path.normpath(args.project) if args.child is not None: n = args.child logging.info('Create child project %d in %s ...', n, path) parent = os.path.join(path, config_filename) if not os.path.exists(parent): raise RuntimeError('No parent project exists in "%s"' % path) filename = os.path.join(path, '%s.%d' % (config_filename, n)) if os.path.exists(filename): raise RuntimeError('Child project %d already exists' % n) logging.info('Copy %s to %s', parent, filename) shutil.copyfile(parent, filename) logging.info('Child project %d init successfully.', n) return logging.info('Create project in %s ...', path) if os.path.exists(os.path.join(path, config_filename)): raise RuntimeError('A project already exists in "%s"' % path) if not os.path.exists(path): logging.info('Make project directory %s', path) os.makedirs(path) src = os.path.normpath(os.path.abspath(args.src)) logging.info('Python scripts base path: %s', src) name = os.path.basename(os.path.abspath(path)) if (args.type == 'pkg') or \ (args.type == 'auto' and os.path.exists(os.path.join(src, '__init__.py'))): logging.info('Project is configured as package') project = Project(name=name, title=name, src=src, is_package=1, entry=args.entry if args.entry else '__init__.py') else: logging.info('Project is configured as standalone application.') project = Project(name=name, title=name, src=src, entry=args.entry) if args.capsule: capsule = os.path.abspath(args.capsule) logging.info('Set project capsule to %s', capsule) else: capsule = os.path.abspath(DEFAULT_CAPSULE) logging.info('Use global capsule as project capsule: %s', capsule) project._update(dict(capsule=capsule)) logging.info('Create configure file ...') filename = os.path.join(path, config_filename) project.save(path) logging.info('Configure file %s created', filename) if sys.argv[0] == 'pyarmor.py': logging.info('Create pyarmor command ...') platname = sys.platform s = make_project_command(platname, sys.executable, sys.argv[0], path) logging.info('PyArmor command %s created', s) logging.info('Project init successfully.')
def _init(args): '''Create a project to manage the obfuscated scripts.''' path = os.path.normpath(args.project) logging.info('Create project in %s ...', path) if os.path.exists(os.path.join(path, config_filename)): raise RuntimeError('A project already exists in "%s"' % path) if not os.path.exists(path): logging.info('Make project directory %s', path) os.makedirs(path) if os.path.isabs(args.src): pro_src = src = os.path.normpath(args.src) else: src = os.path.abspath(args.src) pro_src = relpath(src, os.path.abspath(path)) logging.info('Python scripts base path: %s', src) name = os.path.basename(os.path.abspath(path)) if (args.type == 'pkg') or \ (args.type == 'auto' and os.path.exists(os.path.join(src, '__init__.py'))): logging.info('Project is configured as package') project = Project(name=name, title=name, src=pro_src, is_package=1, entry=args.entry if args.entry else '__init__.py') else: logging.info('Project is configured as standalone application.') project = Project(name=name, title=name, src=pro_src, entry=args.entry) if args.capsule: capsule = os.path.abspath(args.capsule) logging.info('Set project capsule to %s', capsule) else: capsule = os.path.abspath(DEFAULT_CAPSULE) logging.info('Use global capsule as project capsule: %s', capsule) project._update(dict(capsule=capsule)) logging.info('Create configure file ...') filename = os.path.join(path, config_filename) project.save(path) logging.info('Configure file %s created', filename) if sys.argv[0] == 'pyarmor.py': logging.info('Create pyarmor command ...') platname = sys.platform s = make_project_command(platname, sys.executable, sys.argv[0], path) logging.info('PyArmor command %s created', s) logging.info('Project init successfully.')