示例#1
0
def setup_shared_folder():
    if not app.debug and not app.config['TESTING']:
        from gdapi.gdapi import GDAPI
        from default_config import MASTER
        from default_config import ACCOUNTS
        from default_config import PROJECT_ROOT
        # master create shared folder
        master_ga = GDAPI(os.path.join(os.path.dirname(PROJECT_ROOT),
                                        'accounts',
                                        MASTER))
        result = master_ga.query_title(os.path.basename(__name__))
        if len(result) == 1 and result[0]['id']:
            app.config['gd_shared_roo_id'] = result[0]['id']
            return True

        #gd_shared_root_id does not exist, create folder and share to each
        #worker
        root_id = master_ga.create_folder(u'root', os.path.basename(__name__))
        success = master_ga.unshare(root_id)
        app.config['gd_shared_roo_id'] = root_id
        # initial worker threads for each account
        for account in ACCOUNTS:
            tokens = account.split('.')
            perm_id = master_ga.make_user_writer_for_file(root_id,
                                                          ".".join([tokens[0], tokens[1]]))
示例#2
0
def main(argv):
    if len(argv) < 1:
        sys.exit("Usage: {0} <folder_name>".format(argv[0]))
    folder_name = argv[1]

    logger = logging.getLogger('gdapi')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.DEBUG)
    ga = GDAPI('./cred.json')
    ga.create_folder('root', folder_name)
示例#3
0
文件: share.py 项目: tutuca/gdapi
def main(argv):
    if len(argv) < 2:
        sys.exit("Usage: {0} <file_id> <email>".format(argv[0], argv[1]))
    file_id = argv[1]
    email = argv[2]

    logger = logging.getLogger('gdapi')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.DEBUG)
    ga = GDAPI('./cred.json')
    ga.make_user_reader_for_file(file_id, email)
示例#4
0
def main(argv):
    if len(argv) < 1:
        sys.exit("Usage: {0} <title> <description>".format(argv[0]))
    title = argv[1]
    description = argv[2]

    logger = logging.getLogger('gdapi')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.DEBUG)
    ga = GDAPI('./cred.json')
    ga.create_meta_file('root', title, description)
示例#5
0
文件: unshare.py 项目: tutuca/gdapi
def main(argv):
    if len(argv) < 2:
        sys.exit("Usage: {0} <file_id> <perm_id>".format(argv[0], argv[1]))
    file_id = argv[1]
    perm_id = argv[2]

    logger = logging.getLogger('gdapi')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.DEBUG)
    ga = GDAPI('./cred.json')
    ga.unshare(file_id, perm_id)
示例#6
0
def main(argv):
    if len(argv) < 1:
        sys.exit("Usage: {0} <file>".format(argv[0]))
    file_path = argv[1]
    if not os.path.isfile(file_path):
        sys.exit("File is not exist")

    logger = logging.getLogger('gdapi')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.DEBUG)
    ga = GDAPI('./cred.json')
    ga.create_or_update_file('root', file_path, os.path.basename(file_path))
示例#7
0
def main(argv):
    if len(argv) < 2:
        sys.exit("Usage: {0} <file_id> <dest_path>".format(argv[0]))
    file_id = argv[1]
    dest_path = argv[2]
    if os.path.isdir(dest_path):
        sys.exit("Destination is folder")

    logger = logging.getLogger('gdapi')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.DEBUG)
    ga = GDAPI('./cred.json')
    ga.download_file(file_id, dest_path)
示例#8
0
    def test_v2_actor1_reg_w_uninstalled_actor2(self):
        self.init_signup(self.actor1)
        rv = self.app.post(
            '/v2/register',
            headers = {'content-type': 'application/json'},
            data = {
                'identity_code': srv.app.config['IDENTITY_CODE'],
                'email': self.actor1,
                'pubkey': self.actor1_key.publickey().exportKey(),
            })
        jrep = json.loads(rv.data)
        assert 200 == rv.status_code
        assert 200 == jrep.get('code', None)
        assert 'SUCCESS' == jrep['result']['status']
        assert self.actor1_key.publickey().exportKey() == jrep['result']['pubkey']
        assert users[self.actor1]['id'] == jrep['result']['linkedin_id']

        ######################################################
        # actor1 query fid # by name and download file
        ######################################################
        ga = GDAPI(os.path.join(os.path.dirname(PROJECT_ROOT),
                                    'accounts',
                                    users[self.actor1]['cred_file']))
        title = 'Cipherbox LinkedIn Contacts ({0}) DO NOT REMOVE THIS FILE.ioh'.format( self.actor1)
        result = ga.query_title(title, isSharedWithMe=True)
        assert len(result) == 1
        assert result[0]['id']

        contact_file_id = result[0]['id']
        _, temp_path = tempfile.mkstemp()
        success = ga.download_file(contact_file_id, temp_path)
        assert success
        with open(temp_path, 'rb') as fin:
            jobj = json.load(fin)
        os.unlink(temp_path)

        # 1. check 'me' exist
        contacts = jobj['contacts']
        assert contacts['me']
        assert contacts['me']['id'] == users[self.actor1]['id']
        assert contacts['me']['status'] == 'active'
        assert contacts['me']['pubkey'] == self.actor1_key.publickey().exportKey()

        # 2. check actor2 with 'inactive'
        assert contacts[users[self.actor2]['id']]['id'] == users[self.actor2]['id']
        assert contacts[users[self.actor2]['id']]['status'] == 'inactive'
示例#9
0
def update_contact_file(id, reg_item, contact,
                        worker_name='*****@*****.**'):
    from default_config import PROJECT_ROOT
    partner_contact_file_id = contact.get('LinkedIn_Contacts_FID', None)
    if partner_contact_file_id is None:
        return False

    #etag = None
    try:
        ga = GDAPI(os.path.join(os.path.dirname(PROJECT_ROOT), 'accounts', worker_name))
        _, temp_path = tempfile.mkstemp()
        drive_file = ga.download_file(partner_contact_file_id, temp_path)
        #etag = drive_file['etag']

        app.logger.debug("{0} download {1}'s [{2}] to {3}"
                        "".format(worker_name, contact.get('email', None),
                                  partner_contact_file_id, temp_path))
    except Exception as e:
        app.logger.error("[FAIL] {0} download {1}, "
                         "exception: {2}".format(worker_name,
                                                 contact.get('email',
                                                             None),
                                                 repr(e)))
        #[need to implement] how to handle error
        return False


    with open(temp_path, "rb") as fin:
        try:
            jobj = json.load(fin)
        except Exception as e:
            app.logger.error("[FAIL] {0} json.dump(contact_file) {1}, "
                            "exception: {2}".format(worker_name,
                                                    contact.get('email',
                                                                None),
                                                    repr(e)))
            #[need to implement] how to handle error
            return False

    if not jobj or not jobj['contacts']:
        #json format error
        #[need to implement] how to handle error
        return False

    #update contacts content
    jobj['contacts'][id] = reg_item
    #for index in profile:
    #   jobj['contacts'][id][index] = profile[index]
    api_helper._write_contacts_result(temp_path, code=0, contacts=jobj['contacts'])

    try:
        #result = ga.update_file(partner_contact_file_id, temp_path, etag=etag)
        result = ga.update_file(partner_contact_file_id, temp_path)
        app.logger.debug("{0} upload {1}'s [{2}]"
                        "".format(worker_name, contact.get('email', None),
                                partner_contact_file_id))
    except Exception as e:
        app.logger.error("[FAIL] {0} update {1}, "
                            "exception: {2}, gdapi.update_file "
                            "response: {3}".format(workder_name,
                                                contact.get('email', None),
                                                repr(e),
                                                result))
        app.logger.error(result)

    success = ga.unshare(partner_contact_file_id, contact['permid'])
    ga.make_user_reader_for_file(partner_contact_file_id,
                                    contact.get('email', None))
    os.unlink(temp_path)
示例#10
0
 def setUp(self):
     self.gd = GDAPI()
     pass