Skip to content

Commit

Permalink
merge fuocore.utils and feeluown.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Feb 10, 2019
1 parent 617e452 commit 6d8fc8b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 49 deletions.
20 changes: 2 additions & 18 deletions docs/source/dev_quickstart.rst
Expand Up @@ -2,23 +2,8 @@
================
首先,非常感谢您愿意贡献自己的力量让 FeelUOwn 播放器变得更好~

FeelUOwn 播放器目前主要由两个项目组成: feeluown_ 和 feeluown-core_ 。

GUI 相关的逻辑都在 **feeluown** 项目中:包括歌曲/歌单/歌手展示、进度条移动、
专辑图片展示等等。其它逻辑基本都在 **feeluown-core** 项目中。

也就是说,当大家需要修改 GUI 相关功能时,一般只需要将 feeluown 项目 clone
到本地进行开发。而如果是修改其它功能,需要将 feeluown-core 项目 clone
到本地。

.. note::

大家开发或者修改 feeluown-core 相关功能时,不一定要将 feeluown 项目
clone 下来。feeluown-core 自身也是可以独立运行和测试的,关于 feeluown-core
的详细开发文档可以看 `这里 <http://feeluown-core.readthedocs.io>`_ 。

feeluown 推荐的开发流程
-----------------------
推荐的开发流程
--------------

这里假设读者已经对 Git 和 Python 相关工具比较熟悉

Expand Down Expand Up @@ -64,5 +49,4 @@ feeluown 推荐的开发流程
8. (可选)在开发者群中通知大家进行 review

.. _feeluown: http://github.com/cosven/feeluown
.. _feeluown-core: http://github.com/cosven/feeluown-core
.. _廖雪峰的Git教程: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
2 changes: 1 addition & 1 deletion feeluown/__main__.py
Expand Up @@ -9,6 +9,7 @@
import sys

from fuocore import __version__ as fuocore_version
from fuocore.utils import is_port_used

from feeluown.app import App, create_app
from feeluown import logger_config, __version__ as feeluown_version
Expand All @@ -17,7 +18,6 @@
CACHE_DIR, USER_THEMES_DIR, SONG_DIR, COLLECTIONS_DIR
)
from feeluown.rcfile import load_rcfile, bind_signals
from feeluown.utils import is_port_used

logger = logging.getLogger(__name__)

Expand Down
9 changes: 9 additions & 0 deletions feeluown/app.py
Expand Up @@ -20,10 +20,13 @@


class App:
"""App 基类"""

CliMode = 0x0001
GuiMode = 0x0010

def exec_(self, code):
"""执行 Python 代码"""
obj = compile(code, '<string>', 'single')
self._g.update({
'app': self,
Expand All @@ -32,10 +35,16 @@ def exec_(self, code):
exec(obj, self._g, self._g)

def show_msg(self, msg, *args, **kwargs):
"""在程序中显示消息,一般是用来显示程序当前状态"""
logger.info(msg)

@contextmanager
def create_action(self, s):
"""根据操作描述生成 Action (alpha)
设计缘由:用户需要知道目前程序正在进行什么操作,进度怎么样,
结果是失败或者成功。这里将操作封装成 Action。
"""
show_msg = self.show_msg

class Action:
Expand Down
2 changes: 1 addition & 1 deletion feeluown/components/songs_table.py
Expand Up @@ -31,7 +31,7 @@
)

from fuocore.models import ModelExistence
from feeluown.utils import parse_ms
from fuocore.utils import parse_ms
from feeluown.mimedata import ModelMimeData
from feeluown.helpers import use_mac_theme

Expand Down
4 changes: 2 additions & 2 deletions feeluown/ui.py
Expand Up @@ -16,8 +16,9 @@
QVBoxLayout,
)

from fuocore.player import PlaybackMode, State
from fuocore.models import Media
from fuocore.player import PlaybackMode, State
from fuocore.utils import parse_ms

from feeluown.components.separator import Separator
from feeluown.components.playlists import PlaylistsView
Expand All @@ -33,7 +34,6 @@
from feeluown.containers.mpv_widget import MpvOpenGLWidget

from .helpers import use_mac_theme
from .utils import parse_ms

logger = logging.getLogger(__name__)

Expand Down
26 changes: 0 additions & 26 deletions feeluown/utils.py

This file was deleted.

28 changes: 27 additions & 1 deletion fuocore/utils.py
@@ -1,13 +1,39 @@
# -*- coding: utf-8 -*-

from functools import wraps
import logging
import platform
import socket
import time
from functools import wraps


logger = logging.getLogger(__name__)


def parse_ms(ms):
minute = int(ms / 60000)
second = int((ms % 60000) / 1000)
return minute, second


def is_linux():
if platform.system() == 'Linux':
return True
return False


def is_osx():
if platform.system() == 'Darwin':
return True
return False


def is_port_used(port, host='0.0.0.0'):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
rv = sock.connect_ex((host, port))
return rv == 0


def log_exectime(func):
@wraps(func)
def wrapper(*args, **kwargs):
Expand Down

0 comments on commit 6d8fc8b

Please sign in to comment.