コード例 #1
0
ファイル: desktop_preview.py プロジェクト: xiaolin0199/bbt
def _upload_file_http(bucket, username, password, f, town, school, now):
    data = ''
    for chunk in f.chunks():
        data += chunk
    up = upyun.UpYun(bucket, username, password, endpoint=upyun.ED_AUTO)
    try:
        up.usage()
    except upyun.UpYunServiceException:
        bucket = 'oe-test1'
        del up
        up = upyun.UpYun(bucket, username, password)
    ext = os.path.splitext(f.name)[1]
    town_pinyin = '-'.join(pypinyin.lazy_pinyin(town.name))
    school_pinyin = '-'.join(pypinyin.lazy_pinyin(school.name))
    # /year-month-day/school/time.ms.ext
    path = '/%04d-%02d-%02d/%s/%s/%.06f%s' % (now.year, now.month, now.day,
                                              town_pinyin, school_pinyin,
                                              time.time(), ext)
    # print 'save_file: uploading %s to upyun' % path
    try:
        up.put(path, data)
    except upyun.UpYunClientException:
        up = upyun.UpYun(bucket, username, password, endpoint=upyun.ED_CNC)
        up.put(path, data)
    # if DEBUG:
    #     print u'DEBUG screen_upload ---5'
    return path
コード例 #2
0
ファイル: cdn.py プロジェクト: xiaomatech/ops
 def _get_upyun(self):
     up = None
     try:
         up = upyun.UpYun(upyun_config.get('bucket'),
                          username=upyun_config.get('username'),
                          password=upyun_config.get('password'))
     except Exception as e:
         log_error(e)
         try:
             up = upyun.UpYun(upyun_config.get('bucket'),
                              secret=upyun_config.get('secret'))
         except Exception as e:
             log_error(e)
             raise Exception(e)
     return up
コード例 #3
0
    def handle(self, **options):
        USERNAME = '******'
        PASSWORD = '******'
        BUCKETNAME = 'weappimg'
        images = resource_models.Image.objects.filter(
            path__contains='http://chaozhi.weizoom.com')
        print images.count()
        for image in images:
            path = image.path
            print path
            cur_path = path.split('http://chaozhi.weizoom.com')
            if len(cur_path) > 1:
                upyun_path = 'http://weappimg.b0.upaiyun.com' + cur_path[1]

                dir_path = os.path.abspath(
                    '.') + '/static/upload/' + path.split('/')[-2]
                if not os.path.exists(dir_path):
                    os.makedirs(dir_path)
                file_name = path.split('/')[-1]
                file_path = os.path.abspath(
                    '.') + '/static/upload/' + path.split(
                        '/')[-2] + '/' + file_name
                urllib.urlretrieve(path, file_path)

                up = upyun.UpYun(BUCKETNAME,
                                 USERNAME,
                                 PASSWORD,
                                 timeout=300,
                                 endpoint=upyun.ED_AUTO)
                with open(file_path, 'rb') as f:
                    res = up.put(cur_path[1], f)
                    image.path = upyun_path
                    image.save()
コード例 #4
0
ファイル: tasks.py プロジェクト: Alfred-Alan/flask_project
def upload_file(title, file, name):
    # 实例化又拍云对象
    up = upyun.UpYun('mdsave', 'ljq', 'm3QsiAaLhMvB8owYEwdl1l2atviBVF3U')

    # 上传
    # print(type(file.encode('utf-8')))
    # res = up.put('/%s'%name,file)

    with MyMongo(path=host, port=27017, db='md', table='order') as c:
        res = dict(c.find_one({'order_name': title}, {'_id': 0}))['fileList']
        img_list = []
        # 如果存在
        if res:
            img_list = res  # 读取添加
            img_list.append(name)
            c.update_one({'order_name': title},
                         {'$set': {
                             'fileList': img_list
                         }})
            print('添加')
        else:
            img_list.append(name)  # 正常添加
            c.update_one({'order_name': title},
                         {'$set': {
                             'fileList': img_list
                         }})
            print('新增')
    return '成功'
コード例 #5
0
def upload_static_file(file_path, upyun_path, check_exist=False):
    up = upyun.UpYun('weappstatic',
                     USERNAME,
                     PASSWORD,
                     timeout=300,
                     endpoint=upyun.ED_AUTO)

    if check_exist:
        path_index = upyun_path.rfind('/')
        temp_path = upyun_path[:path_index]
        if not temp_path in file_list:
            res = up.getlist(temp_path)
            file_list[temp_path] = res
        res = file_list[temp_path]
        for upfile in res:
            if upfile['name'] == upyun_path[path_index + 1:]:
                print '[upyun] exist file don\'t need to upload file_path', upyun_path
                return

    print '[upyun] need upload file_path:', upyun_path
    with open(file_path, 'rb') as f:
        try:
            res = up.put(upyun_path, f)
        except:
            res = up.put(upyun_path, f)

        return "http://weappstatic.b0.upaiyun.com%s" % upyun_path
コード例 #6
0
 def __init__(self, service=None, username=None, password=None, service_url=None):
     self.service = service or settings.UPYUN_SERVICE
     self.username = username or settings.UPYUN_USERNAME
     self.password = password or settings.UPYUN_PASSWORD
     self.api_url = "http://v0.api.upyun.com"
     self.service_url = service_url or settings.UPYUN_SERVICE_URL
     self.up = upyun.UpYun(service=self.service, username=self.username, password=self.password)
コード例 #7
0
    def test_put_form(self):
        def __put(up, kwargs={}):
            with open('tests/test.png', 'rb') as f:
                res = self.up.put(self.root + 'test.png', f,
                                  checksum=False, form=True,
                                  **kwargs)
                self.assertEqual(res['code'], 200)
                self.assertEqual(res['image-height'], 410)
                self.assertEqual(res['image-width'], 1000)
                self.assertEqual(res['image-frames'], 1)
                self.assertEqual(res['image-type'], 'PNG')

            res = self.up.getinfo(self.root + 'test.png')
            self.assertIsInstance(res, dict)
            self.assertEqual(res['file-size'], '13001')
            self.assertEqual(res['file-type'], 'file')
            self.up.delete(self.root + 'test.png')
            with self.assertRaises(upyun.UpYunServiceException) as se:
                self.up.getinfo(self.root + 'test.png')
            self.assertEqual(se.exception.status, 404)
        # - test conflict upload method
        up = upyun.UpYun(SERVICE, USERNAME, PASSWORD,
                         timeout=100, endpoint=upyun.ED_AUTO)
        kwargs = {'allow-file-type': 'jpg,jpeg,png',
                  'notify-url': 'http://httpbin.org/post',
                  }
        __put(self.up)
        __put(self.up, kwargs=kwargs)
        __put(up)
コード例 #8
0
ファイル: test_upyun.py プロジェクト: ahlfors/python-sdk
 def test_client_exception(self):
     with self.assertRaises(upyun.UpYunClientException):
         e = upyun.UpYun('bucket',
                         username='******',
                         password='******',
                         timeout=100)
         e.up_rest.endpoint = 'e.api.upyun.com'
         e.getinfo('/')
     with self.assertRaises(upyun.UpYunClientException):
         e = upyun.UpYun('bucket',
                         username='******',
                         password='******',
                         timeout=100)
         e.secret = None
         with open('tests/test.png', 'rb') as f:
             e.put(self.root + 'test.png', f, checksum=False, form=True)
コード例 #9
0
	def handle(self, **options):
		USERNAME = '******'
		PASSWORD = '******'
		BUCKETNAME = 'weappimg'
		products = product_models.Product.objects.filter(remark__contains='http://chaozhi.weizoom.com')

		pat = '[p|/]>\n*<img src="(.*?)"'
		for product in products:
			remark = product.remark
			src_lists = re.findall(pat, remark, re.M)
			for src_list in src_lists:
				cur_path = src_list.split('http://chaozhi.weizoom.com')
				if len(cur_path) >1:				
					dir_path = os.path.abspath('.')+ '/static/upload/' + cur_path[1].split('/')[-2]
					if not os.path.exists(dir_path):
						os.makedirs(dir_path)
					file_name = cur_path[1].split('/')[-1]
					file_path = dir_path+'/' +file_name
					urllib.urlretrieve(str(src_list),file_path)

					up = upyun.UpYun(BUCKETNAME, USERNAME, PASSWORD, timeout=300,endpoint=upyun.ED_AUTO)
					with open(file_path, 'rb') as f:
						res = up.put(cur_path[1], f)

			update_remark = remark.replace('http://chaozhi.weizoom.com','http://weappimg.b0.upaiyun.com')
			product.remark = update_remark
			product.save()
コード例 #10
0
 def __init__(self):
     self.up = upyun.UpYun(UPYUN['BUCKETNAME'],
                           UPYUN['USERNAME'],
                           UPYUN['PASSWORD'],
                           timeout=UPYUN['TIMEOUT'],
                           endpoint=upyun.ED_AUTO)
     self.url_prefix = "http://%s.b0.upaiyun.com" % (UPYUN['BUCKETNAME'])
コード例 #11
0
 def _delete_cloud_service_files(self):
     today = datetime.date.today()
     buf = cache.get('cloud-service-clean-date')
     if buf and parse_date(buf) == today:
         # 今天已经运行过一次,不用再运行了
         return
     value = models.Setting.getvalue('desktop-preview-days-to-keep')
     try:
         days = int(value)
     except:
         return
     username = models.Setting.getvalue('desktop-preview-username')
     password = models.Setting.getvalue('desktop-preview-password')
     if not username or not password:
         return
     bucket = cloud_service.generate_bucket_name()
     up = upyun.UpYun(bucket, username, password, endpoint=upyun.ED_AUTO)
     res = up.getlist('/')
     for i in res:
         if i['type'] != 'F':
             continue
         folder_date = parse_date(i['name'])
         if folder_date is None:
             continue
         if (today - folder_date).days > days:
             _delete_upyun_folder(up, '/' + i['name'] + '/')
     cache.set('cloud-service-clean-date', str(today),
               get_timeout('cloud-service-clean-date', None))
コード例 #12
0
def get_list(path):
    upyun_iter = None
    up = upyun.UpYun(target_bucket, target_username, target_password)
    while True:
        while upyun_iter != 'g2gCZAAEbmV4dGQAA2VvZg':
            res = sort_data(path, upyun_iter)
            if res:
                upyun_iter = res[-1]
                for i in res[:-1]:
                    try:
                        if not i['name']:
                            continue
                        new_path = path + i[
                            'name'] if path == '/' else path + '/' + i['name']
                        if i['type'] == 'F':
                            queue.put(new_path)
                        elif i['type'] == 'N':
                            print new_path
                            if save_as_prefix:
                                new_path = save_as_prefix + new_path
                                push_tasks(new_path, up)
                    except Exception as e:
                        print e
            else:
                if not queue.empty():
                    path = queue.get()
                    upyun_iter = None
                    queue.task_done()
        else:
            if not queue.empty():
                path = queue.get()
                upyun_iter = None
                queue.task_done()
            else:
                break
コード例 #13
0
def upload_image_to_upyun(file_path, upyun_path):
    if settings.MODE == 'test':
        BUCKETNAME = 'testweapp'
    else:
        BUCKETNAME = 'weappimg'
    USERNAME = '******'
    PASSWORD = '******'

    if settings.MODE == 'develop':
        return upyun_path

    up = upyun.UpYun(BUCKETNAME,
                     USERNAME,
                     PASSWORD,
                     timeout=300,
                     endpoint=upyun.ED_AUTO)
    try:
        with open(file_path, 'rb') as f:
            try:
                res = up.put(upyun_path, f)
            except:
                res = up.put(upyun_path, f)

            return image_path % (BUCKETNAME, upyun_path)
    except:
        notify_message = u"upload_image_to_upyun error {}".format(
            unicode_full_stack())
        print notify_message
        return upyun_path
    return None
コード例 #14
0
ファイル: collect_usage.py プロジェクト: xiaolin0199/grouptb
 def get_usage(self):
     total = 0
     q = models.OperatorToUpYunGroupTB.objects.all()
     for i in q:
         bucket = 'oebbt-%s' % i.upyungrouptb.grouptb.group_id
         up = upyun.UpYun(bucket,
                          i.operator.username,
                          i.operator.password,
                          endpoint=upyun.ED_AUTO)
         try:
             u = up.usage()
             print bucket, u
             total += int(u)
             obj = models.DetailLog(log_datetime=datetime.datetime.now(),
                                    upyungrouptb=i.upyungrouptb,
                                    usage=int(u))
             obj.save()
         except upyun.UpYunServiceException as e:
             err = json.loads(e.err)
             # {"msg":"bucket not exist","code":40100012,"id":"8c51b9c73d03dba73cb4b097502f2506"}
             if err['code'] == 40100012:
                 print bucket, 'not exist'
                 continue
         except:
             traceback.print_exc()
     total += self.get_test1_usage()
     print 'total:', total
     models.DailyLog(log_datetime=datetime.datetime.now(),
                     usage=total).save()
コード例 #15
0
ファイル: aya.py プロジェクト: yicong1406410220/thbattle
 def on_qrcode(self, image):
     filename = '/qrcode/%s.png' % hex(random.getrandbits(100))
     up = upyun.UpYun(State.options.upyun_bucket,
                      State.options.upyun_username,
                      State.options.upyun_password)
     up.put(filename, image)
     requests.post(
         State.options.bearybot,
         headers={'Content-Type': 'application/json'},
         data=json.dumps({
             'text':
             'QRCode Login for Aya the QQBot',
             'attachments': [{
                 'color':
                 '#ffa500',
                 'images': [{
                     'url':
                     'http://%s.b0.upaiyun.com%s' %
                     (State.options.upyun_bucket, filename)
                 }],
                 'title':
                 datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S'),
                 'text':
                 'Meh...',
             }],
         }))
コード例 #16
0
def main():
    args = parse_command_line()
    up = upyun.UpYun(args.bucket,
                     args.user,
                     args.passwd,
                     timeout=args.timeout,
                     baseurl=(args.baseurl and BASE[args.baseurl]))
    Shell().cmdloop(up, intro='Welcome to upyun shell\n' + '-' * 50)
コード例 #17
0
 def test_client_exception(self):
     with self.assertRaises(upyun.UpYunClientException):
         e = upyun.UpYun('service',
                         username='******',
                         password='******',
                         timeout=100)
         e.up_rest.endpoint = 'e.api.upyun.com'
         e.getinfo('/')
コード例 #18
0
 def test_debug_func(self):
     up = upyun.UpYun(SERVICE,
                      USERNAME,
                      PASSWORD,
                      endpoint=upyun.ED_AUTO,
                      debug=True)
     up.getinfo('/')
     os.remove('debug.log')
コード例 #19
0
def UploadRealFile2Upyun(file, imgurl, kwargs=PLUGINS['UpYunStorage']):
    """ Upload image to Upyun Cloud with Api """

    up = upyun.UpYun(kwargs.get("bucket"), username=kwargs.get("username"), password=kwargs.get("password"), timeout=10, endpoint=upyun.ED_AUTO)
    formkw = { 'allow-file-type': kwargs.get('allow-file-type', 'jpg,jpeg,png,gif') }
    with open(file, "rb") as f:
        res = up.put(imgurl, f, checksum=True, need_resume=True, form=True, **formkw)
    return res
コード例 #20
0
 def setUp(self):
     self.up = upyun.UpYun(SERVICE,
                           USERNAME,
                           PASSWORD,
                           timeout=100,
                           endpoint=upyun.ED_AUTO)
     self.root = rootpath()
     self.up.mkdir(self.root)
コード例 #21
0
ファイル: test_upyun.py プロジェクト: ahlfors/python-sdk
 def test_form_secret_failed(self):
     with self.assertRaises(upyun.UpYunServiceException) as se:
         e = upyun.UpYun(BUCKET,
                         USERNAME,
                         PASSWORD,
                         secret='secret',
                         timeout=100)
         with open('tests/test.png', 'rb') as f:
             e.put(self.root + 'test.png', f, checksum=False, form=True)
     self.assertEqual(se.exception.status, 401)
コード例 #22
0
def UploadImage2Upyun(FilePath, FileData, kwargs=PLUGINS['UpYunStorage']):
    """ Upload image to Upyun Cloud with Api """

    up = upyun.UpYun(kwargs.get("bucket"),
                     username=kwargs.get("username"),
                     password=kwargs.get("password"),
                     timeout=10,
                     endpoint=upyun.ED_AUTO)
    res = up.put(FilePath, FileData)
    return res
コード例 #23
0
def UploadImage2Upyun(FilePath, FileData):
    """ Upload image to Upyun Cloud with Api """

    up = upyun.UpYun(UPYUN.get("bucket"),
                     username=UPYUN.get("username"),
                     password=UPYUN.get("password"),
                     timeout=10,
                     endpoint=upyun.ED_AUTO)
    res = up.put(FilePath, FileData)
    return res
コード例 #24
0
ファイル: delete_upyun_files.py プロジェクト: xiaolin0199/bbt
 def handle(self, *args, **options):
     up = upyun.UpYun('oebbt-%s' % args[0], 'oseasy', 'oseasyoseasy', endpoint=upyun.ED_AUTO)
     print up.usage()
     time.sleep(1)
     res = up.getlist('/')
     for i in res:
         if i['type'] != 'F':
             print i
             continue
         self._delete_upyun_folder(up, '/' + i['name'] + '/')
コード例 #25
0
ファイル: collect_usage.py プロジェクト: xiaolin0199/grouptb
 def get_test1_usage(self):
     username = '******'
     password = '******'
     bucket = 'oe-test1'
     up = upyun.UpYun(bucket, username, password, endpoint=upyun.ED_AUTO)
     try:
         u = up.usage()
         print bucket, u
     except:
         traceback.print_exc()
     return int(u)
コード例 #26
0
 def __init__(self,
              bucket,
              username,
              passwd,
              timeout=30,
              endpoint=upyun.ED_AUTO):
     self.up = upyun.UpYun(bucket,
                           username,
                           passwd,
                           timeout=timeout,
                           endpoint=endpoint)
コード例 #27
0
 def __init__(self,
              bucket=settings.UPYUN_BUCKET,
              username=settings.UPYUN_USER,
              password=settings.UPYUN_PASS,
              timeout=30,
              endpoint=upyun.ED_AUTO):
     self.upyun = upyun.UpYun(bucket=bucket,
                              username=username,
                              password=password,
                              timeout=timeout,
                              endpoint=endpoint)
コード例 #28
0
ファイル: youpai.py プロジェクト: xuefei-heipi/pic_project
 def __init__(self):
     # self.service = 'qiantu-js-css'
     self.service = 'qiantu-yuantu'
     self.username = '******'
     self.password = '******'
     self.up = upyun.UpYun(self.service,
                           self.username,
                           self.password,
                           timeout=30,
                           endpoint=upyun.ED_AUTO)
     self.headers = {}
コード例 #29
0
def upload_audio_file(file_path, upyun_path):
	up = upyun.UpYun('weappstatic', USERNAME, PASSWORD, timeout=300,
			endpoint=upyun.ED_AUTO)
	#print '[upyun] need upload file_path:', upyun_path
	with open(file_path, 'rb') as f:
		try:
			res = up.put(upyun_path, f)
		except:
			res = up.put(upyun_path, f)
		
		return "http://weappstatic.b0.upaiyun.com%s" % upyun_path
コード例 #30
0
ファイル: desktop_preview.py プロジェクト: xiaolin0199/bbt
def _upload_pic_http(host, username, password):
    # print 'testing http', host
    up = upyun.UpYun(bucket, username, password, timeout=5,
                     endpoint=host)
    path = '/diagnose/%.06f.png' % time.time()
    try:
        up.put(path, data)
    except Exception as e:
        return {'address': host, 'method': 'HTTP',
                'status': False, 'msg': str(e)}
    up.delete(path)
    return {'address': host, 'method': 'HTTP', 'status': True}