def main(argv=None): print 'Command line: ', sys.argv if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else: logging.debug('Creating user directory: %s', user_dir) os.makedirs(user_dir) shutil.copyfile(state_src, state_dest) shutil.copyfile(conf_src, confn_dest) global config config = Config(asynk_base_dir=asynk_base_dir, user_dir=user_dir) if len(sys.argv) > 1: run(bbfn=sys.argv[1]) else: print "Running tests against all BBDB files in data/bb/..." bb_data_dir = os.path.join(asynk_base_dir, "test", "gold", "data", "bb") patt = os.path.join(bb_data_dir, "*") test_inputs = glob.glob(patt) test_inputs.append(os.path.abspath('data/bb/bbdb.Non-Existent')) for f in test_inputs: run(f)
def get_args(): """Parse and return the command line arguments.""" parser = argparse.ArgumentParser( description="Terminal remote Spotify player.", epilog=Config.help(), formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "username", help="username associated with your spotify account (email or user id)" ) parser.add_argument("-c --clear_cache", action="store_true", default=False, dest="clear_cache", help="clear the cache") parser.add_argument("-a --clear_auth", action="store_true", default=False, dest="clear_auth", help="clear your authorization tokens") parser.add_argument("-p --config_path", default=None, dest="config_path", help="pass a configuration file") return parser.parse_args()
def main(argv=None): print 'Command line: ', sys.argv print confn_src if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else: logging.debug('Creating user directory: %s', user_dir) os.makedirs(user_dir) shutil.copyfile(state_src, state_dest) shutil.copyfile(confn_src, confn_dest) global config config = Config(asynk_base_dir=asynk_base_dir, user_dir=user_dir) data = None with open(sys.argv[1], "r") as f: data = f.read() print print data vco = vobject.readOne(data) print vco print vco.prettyPrint() con = CDContact(None, vco=vobject.readOne(data), debug_vcf=True) print unicode(con) print "Display Name: ", con.get_disp_name() print "VCO: ", con.init_vco_from_props().serialize()
def __init__ (self, asynk_base_dir, user_dir, bbfn): logging.debug('Getting started... Reading Config File...') self.config = Config(asynk_base_dir, user_dir) self.bb = BBPIMDB(self.config, bbfn) ms = self.bb.get_def_msgstore() self.deff = ms.get_folder(ms.get_def_folder_name())
def __init__(self, config_fn, state_fn, bbfn): logging.debug('Getting started... Reading Config File...') self.config = Config(config_fn, state_fn) self.bb = BBPIMDB(self.config, bbfn) ms = self.bb.get_def_msgstore() self.deff = ms.get_folder(ms.get_def_folder_name())
def __init__(self): logging.debug('Getting started... Reading Config File...') self.config = Config('../config.json', '../state.json') self.ol = OLPIMDB(self.config) self.deff = self.ol.get_def_folder() print "\nHurrah: Name is: ", self.deff.get_name()
def main (argv=sys.argv): parser = setup_parser() uinps = parser.parse_args() # Make the user directory if it does not exist if not os.path.exists(uinps.user_dir): print 'Creating ASynK User directory at: ', uinps.user_dir os.makedirs(uinps.user_dir) # If there is no config file, then let's copy something that makes # sense... if not os.path.isfile(os.path.join(uinps.user_dir, 'state.json')): # Let's first see if there is anything in the asynk source root # directory - this would be the case with early users of ASynK when # there was no support for a user-level config dir in ~/.asynk/ if os.path.isfile(os.path.join(ASYNK_BASE_DIR, 'state.json')): shutil.copy2(os.path.join(ASYNK_BASE_DIR, 'state.json'), os.path.join(uinps.user_dir, 'state.json')) print 'We have copied your state.json to new user director: ', print uinps.user_dir print 'We have not copied any of your logs and backup directories.' else: ## Looks like this is a pretty "clean" run. So just copy the ## state.init file to get things rolling shutil.copy2(os.path.join(ASYNK_BASE_DIR, 'state.init.json'), os.path.join(uinps.user_dir, 'state.json')) # Now copy the config.json file as well. if not os.path.isfile(os.path.join(uinps.user_dir, 'config.json')): shutil.copy2(os.path.join(ASYNK_BASE_DIR, 'config.json'), os.path.join(uinps.user_dir, 'config.json')) state_filen = os.path.join(uinps.user_dir, 'state.json') conf_filen = os.path.join(uinps.user_dir, 'config.json') config = Config(conf_filen, state_filen) config.set_user_dir(uinps.user_dir) setup_logging(config) logging.debug('Command line: "%s"', ' '.join(sys.argv)) try: asynk = Asynk(uinps, config) except AsynkParserError, e: logging.critical('Error in User input: %s', e) quit()
def test_pimdbgc(): config = Config('../app_state.json') # Parse command line options try: opts, args = getopt.getopt(sys.argv[1:], '', ['user='******'pw=']) except getopt.error, msg: print 'python gc_wrapper.py --user [username] --pw [password]' sys.exit(2)
def __init__ (self, asynk_bd, user_d): with open('auth.pwd', 'r') as inf: user = inf.readline().strip() pw = inf.readline().strip() url = inf.readline().strip() self.conf = Config(asynk_base_dir=asynk_bd, user_dir=user_d) self.ex = EXPIMDB(self.conf, user, pw, url) self.cons_f = self.ex.get_def_folder()
def main (argv=None): conf = Config(os.path.join('..', 'config.json'), 'state.test.json') user = raw_input('Enter Username:'******'Password:'******'https://localhost:8443', user, pw) root = '/addressbooks/__uids__/skarrag/addressbook/' # create_contact(cd) show_def_folder(cd, True)
def setup_config(): if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else: logging.debug('Creating user directory: %s', user_dir) os.makedirs(user_dir) shutil.copyfile(state_src, state_dest) shutil.copyfile(conf_src, confn_dest) global config config = Config(asynk_base_dir='../', user_dir=user_dir)
def __init__(self): self.conf = Config(asynk_base_dir=ASYNK_BASE_DIR, user_dir='./') # The following is the 'Gout' group on [email protected] # self.gid = 'http://www.google.com/m8/feeds/groups/karra.etc%40gmail.com/base/41baff770f898d85' # self.gid = # 'http://www.google.com/m8/feeds/groups/karra.etc%40gmail.com/base/6' self.gid = 'http://www.google.com/m8/feeds/groups/karra.etc%40gmail.com/base/204eb63b8e2dad8d' # Parse command line options try: opts, args = getopt.getopt(sys.argv[1:], '', ['user='******'pw=']) except getopt.error, msg: print 'python gc_wrapper.py --user [username] --pw [password]' sys.exit(2)
def __init__ (self): from pimdb_gc import GCPIMDB from state import Config config = Config('../config.json', '../state.json') # The following is the 'Gout' group on [email protected] # self.gid = 'http://www.google.com/m8/feeds/groups/karra.etc%40gmail.com/base/41baff770f898d85' self.gid = 'http://www.google.com/m8/feeds/groups/karra.etc%40gmail.com/base/6' # Parse command line options try: opts, args = getopt.getopt(sys.argv[1:], '', ['user='******'pw=']) except getopt.error, msg: print 'python gc_wrapper.py --user [username] --pw [password]' sys.exit(2)
def __init__ (self, uinps, config=None): """uinps is a Namespace object as returned from the parse_args() routine of argparse module.""" level = string.upper(uinps.log) if level and level != 'INFO': consoleLogger.setLevel(getattr(logging, level)) self.reset_fields() self.validate_and_snarf_uinps(uinps) if config: self.set_config(config) else: self.set_config(Config('./config.json', './state.json')) self.logged_in = False
def run(conf_src): if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else: logging.debug('Creating user directory: %s', user_dir) os.makedirs(user_dir) shutil.copyfile(state_src, state_dest) shutil.copyfile(conf_src, confn_dest) global config config = Config(asynk_base_dir='../../', user_dir=user_dir) suite = unittest.TestLoader().loadTestsFromTestCase(TestStateFunctions) unittest.TextTestRunner(verbosity=2).run(suite)
def main (argv=sys.argv): # Copy a default state.json if this is the first time we are running ASynK if not os.path.isfile('./state.json'): print 'Creating default state.json to hold application status' shutil.copy2('./state.init.json', './state.json'); config = Config('./config.json', './state.json') setup_logging(config) logging.debug('Command line: "%s"', ' '.join(sys.argv)) parser = setup_parser() uinps = parser.parse_args() try: asynk = Asynk(uinps, config) except AsynkParserError, e: logging.critical('Error in User input: %s', e) quit()
def main(argv=None): ## First setup the config files if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else: logging.debug('Creating user directory: %s', user_dir) os.makedirs(user_dir) shutil.copyfile(state_src, state_dest) shutil.copyfile(conf_src, confn_dest) global config config = Config(asynk_base_dir=asynk_base_dir, user_dir=user_dir) ## Now run the write and read test cases suite = unittest.TestLoader().loadTestsFromTestCase(TestBBDBWrite) unittest.TextTestRunner(verbosity=2).run(suite)
def main(argv=sys.argv): parser = setup_parser() uinps = parser.parse_args() # Make the user directory if it does not exist uinps.user_dir = os.path.abspath(os.path.expanduser(uinps.user_dir)) if not os.path.exists(uinps.user_dir): print 'Creating ASynK User directory at: ', uinps.user_dir os.makedirs(uinps.user_dir) config = Config(ASYNK_BASE_DIR, uinps.user_dir) setup_logging(config) logging.debug('Command line: "%s"', ' '.join(sys.argv)) try: asynk = Asynk(uinps, config) except AsynkParserError, e: logging.critical('Error in User input: %s', e) quit()
os.path.dirname(os.path.abspath('__file__')), '../..')) EXTRA_PATHS = [os.path.join(DIR_PATH, 'lib'), os.path.join(DIR_PATH, 'asynk')] sys.path = EXTRA_PATHS + sys.path from state import Config from pimdb_cd import CDPIMDB from contact_cd import CDContact from vobject import vobject asynk_base_dir = os.path.abspath(os.path.join("..", "..")) user_dir = os.path.abspath('user_dir') state_src = os.path.join('..', '..', 'state.init.json') state_dest = os.path.join(user_dir, 'state.json') confn_src = os.path.join('..', '..', 'config', Config.get_latest_config_filen(asynk_base_dir)) confn_dest = os.path.join(user_dir, 'config.json') def usage (): print 'Usage: python test_cd.py' def main (argv=None): print 'Command line: ', sys.argv print confn_src if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else: logging.debug('Creating user directory: %s', user_dir)
# Check the version we're running. check_version() # Clear your auth keys. if args.clear_auth: logger.debug("Clearing authorization tokens") common.clear_auth(args.username) # Reset the cache. if args.clear_cache: logger.debug("Clearing the cache") common.clear_cache(args.username) # Parse config file. logger.debug("Parsing config file %s", args.config_path) config = Config(args.config_path) # Spotify API interface. api = SpotifyApi(args.username) # Display premium warning. if not api.is_premium(): print "This is not a Premium account. Some features may not work." time.sleep(3) # Create Spotify state. sp_state = SpotifyState(api, config) sp_state.load_state() sp_state.init() # Initialize the curses screen.
os.path.join(os.path.dirname(os.path.abspath('__file__')), '../..')) EXTRA_PATHS = [os.path.join(DIR_PATH, 'lib'), os.path.join(DIR_PATH, 'asynk')] sys.path = EXTRA_PATHS + sys.path from state import Config from pimdb_cd import CDPIMDB from contact_cd import CDContact import vobject asynk_base_dir = os.path.abspath(os.path.join("..", "..")) user_dir = os.path.abspath('user_dir') state_src = os.path.join('..', '..', 'state.init.json') state_dest = os.path.join(user_dir, 'state.json') confn_src = os.path.join('..', '..', 'config', Config.get_latest_config_filen(asynk_base_dir)) confn_dest = os.path.join(user_dir, 'config.json') def usage(): print 'Usage: python test_cd.py' def main(argv=None): print 'Command line: ', sys.argv print confn_src if os.path.exists(user_dir): logging.debug('Clearing user directory: %s', user_dir) shutil.rmtree(user_dir) else:
## script standalone from IDLE. Hack it is, but what the hell. DIR_PATH = os.path.abspath(os.path.dirname(os.path.realpath('../Gout'))) EXTRA_PATHS = [os.path.join(DIR_PATH, 'lib'), os.path.join(DIR_PATH, 'asynk'), DIR_PATH] sys.path = EXTRA_PATHS + sys.path from state import Config, AsynkConfigError from asynk import Asynk, AsynkParserError from contact_gc import GCContact conf_fn = '../config.json' state_src = '../state.init.json' state_dest = './state.test.json' shutil.copyfile(state_src, state_dest) config = Config(confn=conf_fn, staten=state_dest) def main (argv=None): init() suite = unittest.TestLoader().loadTestsFromTestCase(TestGCBBSyncFunctions) unittest.TextTestRunner(verbosity=2).run(suite) def blank_uinps (): u = argparse.Namespace() u.db = None u.op = 'startweb' u.bbdb_file = None u.dry_run = False u.remote_db = None u.profile_name = None u.store_id = None