Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if extraargs is None:
extraargs = []
temp_config_name = ct.unittesthelper.create_temp_config(tempdir)
argv = [
"--headerdeps",
name,
"--include",
uth.ctdir(),
"-c",
temp_config_name,
] + extraargs
cachename = os.path.join(tempdir, name)
_reload_ct(cachename)
cap = configargparse.getArgumentParser()
ct.headerdeps.add_arguments(cap)
args = ct.apptools.parseargs(cap, argv)
headerdeps = ct.headerdeps.create(args)
return cachename, temp_config_name, _callprocess(headerdeps, realpaths)
def test_executable_pathname(self):
config_dir = os.path.join(uth.cakedir(), "ct.conf.d")
config_files = [os.path.join(config_dir, "gcc.debug.conf")]
cap = configargparse.getArgumentParser(
description="TestNamer",
formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
default_config_files=config_files,
args_for_setting_config_path=["-c", "--config"],
ignore_unknown_config_file_keys=True,
)
argv = ["--no-git-root"]
ct.apptools.add_common_arguments(cap=cap, argv=argv, variant="gcc.debug")
ct.namer.Namer.add_arguments(cap=cap, argv=argv, variant="gcc.debug")
args = ct.apptools.parseargs(cap, argv)
namer = ct.namer.Namer(args, argv=argv, variant="gcc.debug")
exename = namer.executable_pathname("/home/user/code/my.cpp")
self.assertEqual(exename, "bin/gcc.debug/my")
def test_hunter_follows_source_files_from_header(self):
origcache = ct.dirnamer.user_cache_dir("ct")
tempdir = tempfile.mkdtemp()
_reload_ct(tempdir)
temp_config = ct.unittesthelper.create_temp_config()
argv = ["-c", temp_config, "--include", uth.ctdir()]
cap = configargparse.getArgumentParser()
ct.hunter.add_arguments(cap)
args = ct.apptools.parseargs(cap, argv)
headerdeps = ct.headerdeps.create(args)
magicparser = ct.magicflags.create(args, headerdeps)
hntr = ct.hunter.Hunter(args, headerdeps, magicparser)
relativepath = "factory/widget_factory.hpp"
realpath = os.path.join(uth.samplesdir(), relativepath)
filesfromheader = hntr.required_source_files(realpath)
filesfromsource = hntr.required_source_files(ct.utils.implied_source(realpath))
self.assertSetEqual(filesfromheader, filesfromsource)
# Cleanup
os.unlink(temp_config)
shutil.rmtree(tempdir)
_reload_ct(origcache)
def testGlobalInstances(self, name=None):
p = configargparse.getArgumentParser(name, prog="prog", usage="test")
self.assertEqual(p.usage, "test")
self.assertEqual(p.prog, "prog")
self.assertRaisesRegex(ValueError, "kwargs besides 'name' can only be "
"passed in the first time", configargparse.getArgumentParser, name,
prog="prog")
p2 = configargparse.getArgumentParser(name)
self.assertEqual(p, p2)
def main(argv):
# Chroot and drop privileges first
config.CONFIG = config.Config("dummy")
p = configargparse.getArgumentParser(ignore_unknown_config_file_keys=True, fromfile_prefix_chars='@', add_help=None)
p.add( '--user', dest='user', metavar='USERNAME', help='Switch privileges to this user', default=None)
p.add( '--group', dest='group', metavar='GROUP', help='Switch privileges to this group', default=None)
p.add( '--chroot', dest='chroot', action='store_const', const='chroot', help='Chroot to prefix', default=None)
cfg = p.parse_known_args()
cfg = cfg[0]
if (os.geteuid() == 0):
if (cfg.user):
runningUid = pwd.getpwnam(cfg.user).pw_uid
else:
logging.error("Cannot run as root! Exiting.")
sys.exit(2)
if (cfg.group):
runningGid = grp.getgrnam(cfg.group).gr_gid
if (cfg.chroot):
def load_config():
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
default_config = os.path.join(base_dir, 'config.ini')
p = configargparse.getArgumentParser(
description='Allows to revoke certificates or complete batches or '
'even future uses of issuing addresses. All revoked '
'certificates need to be part of the same transaction.',
default_config_files=[default_config])
p.add('-c', '--config', required=False, is_config_file=True, help='config file path')
group = p.add_mutually_exclusive_group(required='True')
group.add_argument('-s', '--address', action='store_true', help='revoke the issuing_address (from config file)')
group.add_argument('-b', '--batch', type=str, help='revoke a whole batch identified by its transaction id')
group.add_argument('-p', nargs='+', help='a list of certificate pdf files to revoke')
p.add_argument('-d', '--working_directory', type=str, default='.', help='the main working directory - all paths/files are relative to this')
p.add_argument('-a', '--issuing_address', type=str, help='the issuing address with enough funds for the transaction; assumed to be imported in local node wallet')
p.add_argument('-n', '--full_node_url', type=str, default='127.0.0.1:18332', help='the url of the full node to use')
p.add_argument('-u', '--full_node_rpc_user', type=str, help='the rpc user as specified in the node\'s configuration')
p.add_argument('-w', '--full_node_rpc_password', type=str, help='the rpc password as specified in the node\'s configuration')
def get_config():
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
p = configargparse.getArgumentParser(default_config_files=[os.path.join(base_dir, 'conf.ini')])
p.add('-c', '--my-config', required=True, is_config_file=True, help='config file path')
p.add_argument('-k', '--issuer_address', type=str, required=True, help='the issuer\'s Bitcoin address that will be used to issue the certificates')
p.add_argument('-r', '--revocation_address', type=str, required=True, help='the issuer\'s Bitcoin revocation address that can be used to revocate the certificates')
p.add_argument('-d', '--issuer_id', type=str, required=True, help='the issuer\'s publicly accessible identification file; i.e. URL of the file generated by this tool')
p.add_argument('-u', '--issuer_url', type=str, help='the issuers main URL address')
p.add_argument('-l', '--issuer_certs_url', type=str, help='the issuer\'s URL address of the certificates')
p.add_argument('-n', '--issuer_name', type=str, help='the issuer\'s name')
p.add_argument('-e', '--issuer_email', type=str, help='the issuer\'s email')
p.add_argument('-m', '--issuer_logo_file', type=str, help='the issuer\' logo image')
p.add_argument('-o', '--output_file', type=str, help='the output file to save the issuer\'s identification file')
args, _ = p.parse_known_args()
return args
def main(argv=None):
cap = configargparse.getArgumentParser()
Filelist.add_arguments(cap)
args = ct.apptools.parseargs(cap, argv)
headerdeps = ct.headerdeps.create(args)
magicparser = ct.magicflags.create(args, headerdeps)
hunter = ct.hunter.Hunter(args, headerdeps, magicparser)
filelist = Filelist(args, hunter)
filelist.process()
# For testing purposes, clear out the memcaches for the times when main is called more than once.
ct.wrappedos.clear_cache()
ct.utils.clear_cache()
ct.git_utils.clear_cache()
headerdeps.clear_cache()
magicparser.clear_cache()
hunter.clear_cache()
# Using package pyynab to get all the info needed
import configargparse
import os
import random
import re
from ynab import YNAB
from pynYNAB.Client import nYnabClient, BudgetNotFound
from pynYNAB.Entity import AccountTypes
from pynYNAB.budget import MasterCategory, Subcategory, Account, Payee, Transaction
from pynYNAB.connection import nYnabConnection
parser = configargparse.getArgumentParser('pynYNAB')
parser.description='Migrate a YNAB4 budget transaction history to nYNAB \r\n'
parser.add_argument('budget', metavar='BudgetPath', type=str,
help='The budget .ynab4 directory')
parser.add_argument('--budgetname', metavar='BudgetName', type=str,required=False,
help='Migrate to a differently named budget')
args = parser.parse_known_args()[0]
budget_base_name=os.path.basename(args.budget)
budget_path=os.path.dirname(args.budget)
budget_name=re.match(r"(?P.*)~[A-Z0-9]{8}\.ynab4",budget_base_name).groupdict().get('budget_name')
if args.budgetname is not None:
budget_name=args.budgetname
thisynab = YNAB(budget_path,budget_name)
def main(argv=None):
cap = configargparse.getArgumentParser()
ct.headerdeps.add_arguments(cap)
add_arguments(cap)
cap.add("filename", help='File/s to extract magicflags from"', nargs="+")
# Figure out what style classes are available and add them to the command
# line options
styles = [st[:-5].lower() for st in dict(globals()) if st.endswith("Style")]
cap.add("--style", choices=styles, default="pretty", help="Output formatting style")
args = ct.apptools.parseargs(cap, argv)
headerdeps = ct.headerdeps.create(args)
magicparser = create(args, headerdeps)
styleclass = globals()[args.style.title() + "Style"]
styleobject = styleclass(args)