Skip to content

Commit

Permalink
upgrade to v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kfrancischen committed Jul 16, 2021
1 parent 8d022ce commit a06c61c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
16 changes: 15 additions & 1 deletion doc/docs/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,24 @@ write_json_to_file(json_obj, file_name)
```python
read_json_from_file(file_name)
```
* Description: read a json dictionary with given type from a file.
* Description: read a json dictionary from a file.
* Arguments:
1. file_name: the name of the file containing the json dictionary.

```python
write_lined_txt_to_file(data, file_name)
```
* Description: write a list as lines to a file.
* Arguments:
1. data: the list to be written.
2. file_name: the output file name.

```python
read_lined_txt_from_file(file_name)
```
* Description: read a list of lines from a file.
* Arguments:
1. file_name: the name of the file containing the list.

### Documentation of Protobuf Utilities
THe following functions are related to protobuf.
Expand Down
6 changes: 6 additions & 0 deletions pslx/test/util/test_file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class FileUtilTest(unittest.TestCase):

TEST_DATA_PATH = '/galaxy/bb-d/pslx/test_data/test.json'
TEST_DATA_PATH_1 = '/galaxy/bb-d/pslx/test_data/test.txt'

def test_base_name(self):
file_name = 'foo/bar/file.txt'
Expand Down Expand Up @@ -74,3 +75,8 @@ def test_json_to_file(self):
}
FileUtil.write_json_to_file(json_obj=data, file_name=self.TEST_DATA_PATH)
self.assertDictEqual(data, FileUtil.read_json_from_file(file_name=self.TEST_DATA_PATH))

def test_lined_txt_to_file(self):
data = ['123', '234']
FileUtil.write_lined_txt_to_file(data=data, file_name=self.TEST_DATA_PATH_1)
self.assertEqual(data, FileUtil.read_lined_txt_from_file(file_name=self.TEST_DATA_PATH_1))
9 changes: 9 additions & 0 deletions pslx/util/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ def read_json_from_file(cls, file_name):
else:
return {}

@classmethod
def read_lined_txt_from_file(cls, file_name):
data = gclient_ext.read_txt(file_name)
return [item.strip() for item in data.rstrip().split('\n')]

@classmethod
def write_lined_txt_to_file(cls, data, file_name):
gclient.write(path=file_name, data='\n'.join(data))

@classmethod
def parse_timestamp_to_dir(cls, timestamp):
timestamp_list = [str(timestamp.year), '%02d' % timestamp.month, '%02d' % timestamp.day,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def run(self):

setuptools.setup(
name="pslx",
version="2.2",
version="2.3",
scripts=['compile_protos.sh'],
cmdclass={
'install': CustomInstallCommand,
Expand Down

0 comments on commit a06c61c

Please sign in to comment.